/**************************************************************************
 * @doc CITI
 * @module CITISrc |
 * Source code for the CITI handling functions.
 *
 * Product         :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   :   SoftPay Development Team ASPAC ADC.
 * <nl>Notes       :
 *
 * @head3 CITI Functions |
 * @index | CITI
 * @end
 *
 * Copyright (c) 1996-2005 by VeriFone Inc. All rights reserved.
 *
 * No part of this software may be used, stored, compiled, reproduced,
 * modified, transcribed, translated, transmitted, or transferred, in any form
 * or by any means whether electronic, mechanical, magnetic, optical,
 * or otherwise, without the express prior written permission of VeriFone, Inc.
 *
 * Revision History
 * ------------------------------------------------------------------------
 *	Date						Author							Remarks
 *	13-Dec-2005		CHIA Lee Chyi				Modified function inSetCITITransFields for ETEC test case REQ02_05_01
 *	13-Dec-2005		CHIA Lee Chyi				Modified function inSetCITITransFields for ETEC test case REQ02_05_01
 * 14-Dec-2005		CHIA Lee Chyi				Modified function inSendReceiveCITI for ETEC test case REQ02_04_01
 * 14-Dec-2005		CHIA Lee Chyi				Modified function inCITIPIPAnalyse for code enhancements
 ********************************************************************************/
#ifdef IMAM_LOG
#ifndef LOGSYS_FLAG
#define LOGSYS_FLAG
#endif
#endif

#include <project.h>
#define CITI_C

#include <sizes.h>
#include <aclconio.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>    //liem
#include <acldev.h>
#include <aclstr.h>
#include <aclutil.h>
#include <prot8583.h>
#include <define.h>
#include <transact.h>
#include <dbmgr.h>
#include <mdlfuncs.h>
#include <svc.h>
#include <power.h> 

#include <entry.h>    
#include <pinpad.h>  
#include <protocol.h>
#include <packet.h>
#include <tran.h>
#include <comm.h>
#include <modem.h>
#include <ppt.h>
#include <piputl.h>
#include <pipmsg.h>
#include <isoutl.h>
#include <isoload.h>
#include <ifldtbl.h>
#include <msg.h>
#include <msgfuncs.h>
#include <bdt.h>
#include <hdt.h>
#include <trt.h>
#include <mht.h>
#include <iit.h>
#include <accum.h>
#include <form.h>
#include <date.h>
#include <mem.h>
#include <spdebug.h>
#include <funcids.h>
#include <pbatch.h>
#include <errno.h>
#include <ascii.h>
#include <amexhost.h>
#include <pct.h>
#include <formater.h>
#include <table.h>
#include <string.h>
#include <confio.h>
#include <aclfile.h>
#include <format.h>
#include <spamsg.h>
#include <oper.h>
#include <batmsg.h>
#include <ui.h>
#include <tct.h>
#include <multilng.h>
#include <logo.h>
#include <settlbat.h>
#include <msgclrk.h>
#include <msgshf.h>
#include <menufunc.h>
#include <mit.h>
#include <applidl.h>
#include <tblutil.h>
#include <menus.h>
#include <Validt.h>
#include <stats.h>
#include <cardmsg.h>
#include <card.h>
#include <msg.h>
#include <define.h>
#include <entry.h>
#include <pinpad.h>
#include <ctype.h>
#include <gds.h>
#include <power.h>
#include <tip.h>
#include <iso8583.h>
#include <beetle.h>
#include <xmodem.h>
#include <modemmsg.h>
#include <scdefine.h>
#include <rcptsegs.h>
#include <operate.h>
#include <cdt.h>///ivan
#include <battery.h>
#include <printer.h>
#include <rs232.h>
#include "..\IMAMSrc\ImamSrc.h"
#include "..\IMAMSrc\UclCode.h"
#include "..\IMAMSrc\ImamUtil.h"
#include "..\IMAMSrc\ImamMenu.h"
#include "..\IMAMSrc\ImamWave.h"

#ifdef VXEMVAPP
#include <libvoy.h>
#include <cardslot.h>
#include <EMVCWrappers.h>
#include <common.h>
#include <EMVCStructs.h>
#include <vxemvap.h>
#include <emvlib.h>
#include <estfuncs.h>
#include <mvtfuncs.h>
#include <mvt.h>
#include <est.h>
#include "../EMVSrc/EMVids.h"
#include "../EMVSrc/EMVsrcdef.h"
#include "../EMVSrc/EMViso.h"
#include "../EMVSrc/EMVprnt.h"
#endif

#include "..\cpacsrc\cpacmsg.h"
#include "..\cpacsrc\cpacids.h"
#include "..\cpacsrc\cpacsrc.h"
#include "..\cpacsrc\cpac.h"
#include "..\cpacsrc\cpacsize.h"
#include "..\cpacsrc\cpacprnt.h"
#include "..\cpacsrc\cpacoper.h"


#include "..\CITIsrc\CITImsg.h"
#include "..\CITIsrc\CITIsrc.h"
#include "..\CITIsrc\CITIids.h"
#include "..\CITIsrc\CITIsize.h"

//#include "..\EPPSrc\EPPSrc.h"/
//#include "..\CASHSrc\CASHSrc.h"
//#include "..\CABKSrc\CABKSrc.h"

#ifdef VXEMVAPP
#include <emvfuncs.h>
#include "..\EMVsrc\EMVmsg.h"
#endif

#ifdef AMEX_SOC

#include "..\axapsrc\axapids.h"

#endif /* AMEX_SOC */


extern MenuItem	   *pmeScrollItem;
extern unsigned long lnImamMenuItem; 

extern int inNoDisp;
extern VS_BOOL fDisplayIdleMenu;
extern int inGlobalMerchantHandle;
extern long lnCPACMiddleCondition;
extern int inGCPACHostSelectedIndex;

extern CPAC_SETTLE_HEADER srCPACSettleHeader;
extern CPAC_SETTLE_MIDDLE srCPACSettleMiddle;
extern CPAC_SETTLE_BOTTOM srCPACSettleBottom;

extern VS_BOOL fImamTag5F34Exist; // for INT15
extern VS_BOOL fImamCTLTag5F34Exist;

//For EMV data
#ifdef VXEMVAPP
extern int inGlobalNumberScripts;
field_struct srFieldEMV55ISOFDT;
unsigned char szEMVField55[EMV_FIELD55_SIZE + 1];
extern long lnTranTitleMessage;

field_struct srFieldEMV23ISOFDT;  // jrd 05212005
char szEMVField23[EMV_FIELD23_SIZE + 1];
#endif /* VXEMVAPP */

VS_BOOL fImamNeedToSendTC = VS_FALSE;

VS_BOOL fSettmentFlag= VS_FALSE;

int inSelectTran = VS_ERROR;
extern int inImamLineNumber;
extern SMenu *ImamActiveMenu;
extern char szMifareData[60];
#define PRINTER_350         3

ISOLOAD srCITILoadDataFuncs[] = {

    2,    vdLoadField02,
    3,    vdDummy,
    4,    vdLoadCPACField04,
    11,    vdLoadField11,
    12,    vdLoadField12,
    13,    vdLoadField13,
    14,    vdLoadCPACField14,
    #ifdef VXEMVAPP
	22, vdLoadEMVField22,
   #else
   	22, vdLoadCPACField22,
   #endif
   #ifdef VXEMVAPP
	23, vdLoadCITIEMVField23,
   #endif
    24,    vdLoadCPACField24,
    25,    vdLoadField25,
    35,    vdCITILoadField35,
    37,    vdLoadCPACField37,
    #ifdef VXEMVAPP
	38, vdEMVLoadField38,
   #else
   	38, vdLoadField38,
   #endif
    39,    vdLoadCPACField39,
    41,    vdLoadCPACField41,
    42,    vdLoadCPACField42,
    44,    vdDummy,
    45,    vdLoadField45,
    48,    vdLoadCITIField48,
	52,    vdLoadCPACField52,
    54,    vdLoadCITIField54,
    #ifdef VXEMVAPP
	55, vdLoadEMVField55,
   #endif /* VXEMVAPP */
    60,    vdLoadCPACField60,
    61,    vdLoadCPACField61,
    62,    vdLoadCPACField62,
    63,    vdLoadCITIField63,
	64,    vdLoadCPACField64
};


/*********************************************************************************************
* @func int | inCPACCreateVariantStruct63 |
* This routine takes care of allocating the space and loading the Variant field
* table 63 for CPAC.
*
* @devnote This is an obHost function
*
* @rdesc Returns the success.
* @flag int | VS_SUCCESS
* @flag int | VS_ERR
* @end
**********************************************************************************************/

int inCITICreateVariantStruct63(void) { //LIEM : DO NOT USE THIS, USE CPAC INSTEAD
    short i;
    variant_struct* tmp;
//spqalog003 change CPAC_TABLE63_SIZE to CITI_TABLE63_SIZE
    if ((tmp = (variant_struct *) pchAlloc(CITI_TABLE63_SIZE * sizeof(variant_struct))) == NULL_CH) {
        ACTIVITY_LOG("Variant 60 memory alloc!");
        return (VS_ERR);
    }

    psrVariant63 = tmp;

    for (i = 0; i < CITI_TABLE63_SIZE; i++) {
        tmp->convert_idx = AV3_STR;
        tmp->reference = (void *) srISO.pszField63;
        tmp->var_sz = sizeof(srISO.pszField63);
        if (i < 5) {
            tmp->variant2 = 500;
            tmp->packet_sz = 90;
        } else if ( i != CITI_TABLE63_SIZE-1) { //: slight change
            tmp->variant2 = 510;
            tmp->packet_sz = 90; /* 40-> 90 CPAC_UNBKL */
        } else {
            tmp->variant2 = 510;
            tmp->packet_sz = 90; /* 40-> 90 CPAC_UNBKL */
        }

        switch (i) {
        case 0:
            tmp->variant1 = 92;
            break;
        case 1:
            tmp->variant1 = 93;
            break;
        case 2:
            tmp->variant1 = 94;
            break;
        case 3:
            tmp->variant1 = 96;
            break;
        case 4:
            tmp->variant1 = 97;
            break;
        case 5:
            tmp->variant1 = 96;
            break;
        case 6:
            tmp->variant1 = 93;
            break;
        case 7:
            tmp->variant1 = 94;
            break;
	case 8:
	     tmp->variant1=00;
         tmp->variant2=210;
	     tmp->packet_sz=143;
	     break;
	case 9:
	     tmp->variant1=02;
         tmp->variant2=210;
	     tmp->packet_sz=143;  //spqalog036
	     break;
	case 10:
	     tmp->variant1=38;
         tmp->variant2=110;
	     tmp->packet_sz=143;  //spqalog039
	     break;
		case 11:tmp->variant1 = 20;  // Refund Permata
			tmp->variant2 = 210;
			tmp->packet_sz = 90;
			break;
		case 12:
			tmp->variant1 = 00;  //SALE AIRLINE REQUEST, Private Label, CVV2
			tmp->variant2 = 200;
			tmp->packet_sz = 90;
#ifdef IMAM_CR2
			tmp->convert_idx = AV3_AV3;
#endif
			break;
		case 13:tmp->variant1 = 00;  //EMA : PURCHASE
			tmp->variant2 = 210;
			tmp->packet_sz = 99;
			break;
		case 14:tmp->variant1 = 50;  //EMA : ISI ULANG/PAYMENT
			tmp->variant2 = 210;
			tmp->packet_sz = 99;
			break;
		case 15:tmp->variant1 = 80;  //EMA : REGISTRASI MB
			tmp->variant2 = 210;
			tmp->packet_sz = 99;
			break;
		case 16:tmp->variant1 = 31;  //EMA : INFO SALDO
			tmp->variant2 = 210;
			tmp->packet_sz = 99;
			break;
		case 17:tmp->variant1 = 38;  //EMA : MINI STATEMENT
			tmp->variant2 = 210;
			tmp->packet_sz = 99;
			break;
		case 18:tmp->variant1 = 39;  //EMA : INFO CCard
			tmp->variant2 = 310;
			tmp->packet_sz = 99;
			break;
		case 19:tmp->variant1 = 38;  //EMA : INFO BILL
			tmp->variant2 = 310;
			tmp->packet_sz = 99;
			break;
		case 20:tmp->variant1 = 40;  //EMA : TRF 2 CIF
			tmp->variant2 = 210;
			tmp->packet_sz = 99;
			break;
		case 21:tmp->variant1 = 49;  //EMA : TRF 2 OTHERS BANK
			tmp->variant2 = 210;
			tmp->packet_sz = 99;
			break;
		case 22:tmp->variant1 = 00;  //EMA : PURCHASE
			tmp->variant2 = 110;
			tmp->packet_sz = 99;
			break;
		case 23:tmp->variant1 = 50;  //EMA : ISI ULANG/PAYMENT
			tmp->variant2 = 110;
			tmp->packet_sz = 99;
			break;
		case 24:tmp->variant1 = 80;  //EMA : REGISTRASI MB
			tmp->variant2 = 110;
			tmp->packet_sz = 99;
			break;
		case 25:tmp->variant1 = 31;  //EMA : INFO SALDO
			tmp->variant2 = 110;
			tmp->packet_sz = 99;
			break;
		case 26:tmp->variant1 = 38;  //EMA : MINI STATEMENT
			tmp->variant2 = 110;
			tmp->packet_sz = 99;
			break;
		case 27:tmp->variant1 = 39;  //EMA : INFO CCard
			tmp->variant2 = 110;
			tmp->packet_sz = 99;
			break;
		case 28:tmp->variant1 = 38;  //EMA : INFO BILL
			tmp->variant2 = 110;
			tmp->packet_sz = 99;
			break;
		case 29:tmp->variant1 = 40;  //EMA : TRF 2 CIF
			tmp->variant2 = 110;
			tmp->packet_sz = 99;
			break;
		case 30:tmp->variant1 = 49;  //EMA : TRF 2 OTHERS BANK
			tmp->variant2 = 110;
			tmp->packet_sz = 99;
			break;
        case 31:
            tmp->variant1 = 92 + STOP;
            break;
        }
        tmp++;
    }
    srBaseIsoFDT[FIELD63_POSITION].packet_sz = 0;
    srBaseIsoFDT[FIELD63_POSITION].var_sz = 0;
    srBaseIsoFDT[FIELD63_POSITION].convert_idx = VARIANT;
    srBaseIsoFDT[FIELD63_POSITION].reference = (void *) psrVariant63;

    /*  psrVariant63[] =
    {
    { 92,   500,    90,      AV3_STR,    VARIABLE(srISO.pszField63) },
    { 93,   500,    90,      AV3_STR,    VARIABLE(srISO.pszField63) },
    { 94,   500,    90,      AV3_STR,    VARIABLE(srISO.pszField63) },
    { 96,   500,    90,      AV3_STR,    VARIABLE(srISO.pszField63) },
    { 97,   500,    90,      AV3_STR,    VARIABLE(srISO.pszField63) },
    { 96,   510,    40,      AV3_STR,    VARIABLE(srISO.pszField63) },
    { 93,   510,    40,      AV3_STR,    VARIABLE(srISO.pszField63) },
    { 94,   510,    40,      AV3_STR,    VARIABLE(srISO.pszField63) },
    { 92,   510,    40,      AV3_STR,    VARIABLE(srISO.pszField63) },
    };
    */
    return(VS_SUCCESS);
}





/*********************************************************************************************
* @func void | vdAddCITIFunctions |
*       Adds the CITI specific functions to the function table flexi record.
* @end
**********************************************************************************************/

void vdAddCITIFunctions( void )
{
	inAddMessageFileName( CITI_NAME_ID, "dmsg");
	inAddFunctionPointer( CITI_INIT_PACKET , (PFI) vdInitializeCITI);

	inAddFunctionPointer(CHK_TRAN_ALLOWED, inCheckAllowed);

	inAddFunctionPointer(CITI_VALIDATE_TRAN, inCitiValidateTransaction);
	inAddFunctionPointer(CHK_INV, enableinvoice);///ivan
	inAddFunctionPointer(CHK_INVEPP, enableinvoiceepp);///ivan
	inAddFunctionPointer(CHK_INVCASH, enableinvoicecash);///ivan
	inAddFunctionPointer(CHK_INVCABK, enableinvoicecabk);///ivan
	inAddFunctionPointer(CHK_INVAMEX, enableinvoiceAMEX);///ivan
	inAddFunctionPointer(CHK_INVJCB, enableinvoiceJCB);///ivan
	inAddFunctionPointer(CHK_INVDINERS, enableinvoiceDINERS);///ivan
	inAddFunctionPointer(CITI_REPRINT_FILE_COPY, inCITIReprintFileCopy);
	inAddFunctionPointer(CITI_SET_VOID_ONLINE, inSetCITIVoidOnline);
	inAddFunctionPointer(EEP_END_COMM, inEndEPPComm);
	inAddFunctionPointer(CITI_REGULAR_PROMO, inSelectRegularPromo);
	inAddFunctionPointer(CITI_EPP_GET_TENOR, inGetCITIEPPTenor);
	inAddFunctionPointer(EPP_GET_CASHBACK_AMOUNT,inGetEPPCashBackAmount);
	inAddFunctionPointer(EPP_GET_CASH_AMOUNT, inGetEPPCashAmount);
	inAddFunctionPointer(GET_INVOICE_NUMBER1, inGetInvoiceNumber1);///ivan
	inAddFunctionPointer(VALIDATE_HOST, inCheckHost);///ivan
	inAddFunctionPointer(BOP_SETTLE_ALL_HOSTS, inBOPSettleAllHosts);

	inAddFunctionPointer(EDIT_SIG, inCITIEditSIGOperation);
	inAddFunctionPointer(EDIT_ETT, inCITIEditETTOperation);
	inAddFunctionPointer(CITI_CHOOSE_SALE_OR_EPP, inSelectSaleEpp);
	inAddFunctionPointer(GET_CARD_FIELDS1, inEnterCardData1);
	inAddFunctionPointer(GET_CARD_FIELDS2, inEnterCardData2);
	inAddFunctionPointer(GET_CARD_FIELDS3, inEnterCardData3);
	inAddFunctionPointer(GET_CARD_BIN1, (PFI_TO)inGetCardBin1);
	inAddFunctionPointer(GET_CARD_BIN2, (PFI_TO)inGetCardBin2);
	inAddFunctionPointer(GET_CARD_BIN3, (PFI_TO)inGetCardBin3);
	inAddFunctionPointer( VALIDATE_SWIPED_CARD1, inCPACValidateSwipedCard1);
	inAddFunctionPointer( VALIDATE_SWIPED_CARD2, inCPACValidateSwipedCard2);
	inAddFunctionPointer( VALIDATE_SWIPED_CARD3, inCPACValidateSwipedCard3);
	inAddFunctionPointer(LOAD_GET_CDT1, (PFI_TO)inLoadGetCDTIndex1);
	inAddFunctionPointer(LOAD_GET_CDT2, (PFI_TO)inLoadGetCDTIndex2);
	inAddFunctionPointer(LOAD_GET_CDT3, (PFI_TO)inLoadGetCDTIndex3);
	inAddFunctionPointer(VALIDATE_MANUAL_NO1, (PFI_TO)inValidateManualCardNo1);
	inAddFunctionPointer(VALIDATE_MANUAL_NO2, (PFI_TO)inValidateManualCardNo2);
	inAddFunctionPointer(VALIDATE_MANUAL_NO3, (PFI_TO)inValidateManualCardNo3);
	inAddFunctionPointer(CITI_SELECT_AND_LOAD_HOST, inCITISelectAndLoadHost);
//	inAddFunctionPointer(EPP_SELECT_HOST, inEPPSelectAndLoadHost);
/*	inAddFunctionPointer(CASH_SELECT_HOST, inCASHSelectAndLoadHost);*/
/*
	inAddFunctionPointer(CASH_BACK_SELECT_HOST, inCABKSelectAndLoadHost);*/
	inAddFunctionPointer(CITI_END_MODEM, inCITIEndModem);
	inAddFunctionPointer(CITI_SETTLE_REPRINT, inCITIReprintSettleRep);
	inAddFunctionPointer(CITI_SETTLEMENT_FLAG_TRUE, inSettlementFlagTrue);
	inAddFunctionPointer(CITI_SETTLEMENT_FLAG_FALSE, inSettlementFlagFalse);
	inAddFunctionPointer(CITI_CNG_SALE_COMP_MSG, inChangeSaleCompMsgforVoid);
	inAddFunctionPointer(CITI_BANK_REFERRAL, inCITIBankReferral);

	inAddFunctionPointer(CITI_EDIT_COMM, inCITIEditCOMOperation); /* LeeChyi - 02122005: Added */
	inAddFunctionPointer(CITI_EDIT_PABX, inCITIEditPABXOper); //KiaSoon 150206 Added
	inAddFunctionPointer(CITI_PRINT_CONFIG, inCITIPrintConfigOper); //KiaSoon 150206 Added

	inOverloadFieldID(SEND_CPAC_PACKET, (PFI_TO) inSendReceiveCITI);
	inOverloadFieldID(DISPLAY_AT_IDLE, inCITIDisplayAtIdle);
	inOverloadFieldID(START_CARD_TRAN, inCITIStartCardTxn);
	inOverloadFieldID(CPAC_PRINT_RECEIPT_TOP, inCITIPrintReceiptTop);
	inOverloadFieldID(CPAC_PRINT_RCPT_BOTTOM, inCITIPrintReceiptBottom);
	//inOverloadFieldID(CPAC_SETTLE_A_HOST, inCITISettleAHost);
	inOverloadFieldID(CPAC_PRINT_SUMMARY_REPORT, inCITISummaryReportOperation);
	inOverloadFieldID(PRINTER_CHECK, inCITIPrinterCheck);
	inOverloadFieldID(GET_INVOICE_NUMBER, inCITIGetInvoiceNumber);
	inOverloadFieldID(CPAC_GET_INV_NUM, inCITIGetInvNum);
	inOverloadFieldID(CPAC_REPRINT_SETT_REPORT, inCITIallReprintSettleReport);
	inOverloadFieldID(UPDATE_ACCUM_VALUES, (PFI_TO) inCITIUpdateOfflineAccum);
	inOverloadFieldID(CUST_COMPUTE_DISPLAY_TOTAL, inCITICustComputeAndDispTotal);
	inOverloadFieldID(CPAC_VALIDATE_VOID, inCITIValidateVoid);
	inOverloadFieldID(DISPLAY_SWIPE_CARD_INFO, inCITICustDisplaySwipeCardInfo);
}

/*********************************************************************************************
* @func int | inSetCITITransFields |
* This routine takes care of loading the Host Specific BitMap
* corresponding to the Transaction that is passed as input to
* this routine.
*
* @parm TRANSACTION_OBJECT * | pobTran |
*       This is the transaction object.
*
* @parm int | host |
*       This is the host ???.
*
* @parm int | inTransCode |
*       This is the inTransCode ???.
*
* @parm char * | szProcCode |
*       This is the szProcCode ???.
*
* @rdesc Returns the success.
* @flag int | VS_SUCCESS
* @end
**********************************************************************************************/
int inSetCITITransFields(TRANSACTION_OBJECT* pobTran,int host,unsigned int inTransCode,char* szProcCode) 
{
    char szTrackPriority[TRACKS_ALLOWED + 1];//1.4
    char chTrackNum;
    
    /* Get the transaction type from the GDS */
    if ((inTransCode != 0x1500) && (inTransCode != 0x1600) && (pobTran->srBRec.inCode != BATCH_UPLOAD))
        memcpy(srISO.pszField03, szProcCode, PROC_CODE_SIZE);

    /* Set the optional bit map fields */
    memset(stOptionalMap, 0, BIT_MAP_SIZE);
	LOG_PRINTFF((0x08L, "inSetCITITransFields CALLED"));

	if ((pobTran->srBRec.inCode != LOGON) && 
		(pobTran->srBRec.inCode != TEST) && 
		(pobTran->srBRec.inCode != CLS_BATCH) &&  
		(pobTran->srBRec.inCode != IMAM_LOGON) &&  //edi add
		(pobTran->srBRec.inCode != CLS_BATCH_UPLOAD)
		){
		if (fGetImamSelectAcc()) srISO.pszField03[1] = pobTran->srBRec.chECI;

		if (pobTran->srBRec.fManual == VS_TRUE ||
			pobTran->srBKey.fVoided == VS_TRUE ||
			pobTran->srTRTRec.TransactionCode == SALE_OFFLINE ||
			pobTran->srTRTRec.TransactionCode == ADJUST ||
			pobTran->srTRTRec.TransactionCode == REFUND_OFFLINE||
			pobTran->srTRTRec.TransactionCode == CPAC_PHIL_ADJUST ||      //1.4_citiphil_don_26feb
			pobTran->srTRTRec.TransactionCode == TIP_ADJUST ||
			pobTran->srTRTRec.TransactionCode == ADD_TIP_OFFLINE ||
			pobTran->srTRTRec.TransactionCode == TC_UPLOAD || /*Thiru, TC Uplaod, no DE 35 */
			pobTran->srBRec.inCode == BATCH_UPLOAD ||
			pobTran->srTRTRec.TransactionCode == PRE_COMP
			)  { // 1.4_dk23
            map_set(stOptionalMap, 2);
            map_set(stOptionalMap, 14);
            map_reset(stOptionalMap, 35);            /* CPAC_UNBKL added */
			map_reset(stOptionalMap, 45);
        } else {
            strcpy(szTrackPriority, szGetTracks());
            chTrackNum = *(strpbrk(szTrackPriority, "123"));                                //1.4
            switch (chTrackNum) {
                //1.4
            case TRACK_ONE:
                map_set(stOptionalMap, 45);
                break;
            case TRACK_TWO:
                map_set(stOptionalMap, 35);
                break;
            default:
                if (strlen(pobTran->srBRec.stT2Data) < 1)
                    map_set(stOptionalMap, 45);
                else
                    map_set(stOptionalMap, 35);
            }
            if (inGetTipProcessing() > TIP_OFF)
                map_set(stOptionalMap, 54);
		
			if ((strstr(szTrackPriority, "1") != (char *) NULL) &&
				(fGetImamHostTrack1Req() == VS_TRUE)
				){  
					if (pobTran->srBRec.fT1Data == VS_TRUE){
						map_set(stOptionalMap, 45);
					}
			}
        }

	#ifdef VXEMVAPP
     if((pobTran->srBRec.inChipStatus == EMV_CARD) &&
     	 ((pobTran->srTRTRec.TransactionCode == SALE) ||
     	 (pobTran->srTRTRec.TransactionCode == CITI_EPP_SALE) ||  //spqalog008
     	  (pobTran->srTRTRec.TransactionCode == TC_UPLOAD) ||
     	 /*(pobTran->srTRTRec.TransactionCode == SALE_OFFLINE) || */
     	 (pobTran->srTRTRec.TransactionCode == AUTH_ONLY) ||  //KiaSoon 070206 Started: To Send DE55 for Pre-Auth, Card verification
		 (pobTran->srTRTRec.TransactionCode == IMAM_CARDVER) ||
     	// (pobTran->srTRTRec.TransactionCode == REFUND) ||
     	 (pobTran->srTRTRec.TransactionCode == PRE_AUTH) ||  // jrd 05212005
     	  (pobTran->srBKey.fVoided == VS_TRUE)||	//jrd spqalog051
     	 (pobTran->srBRec.inCode == BATCH_UPLOAD)||
     	  (pobTran->srBRec.inCode == CITI_EPP_CASHBACK)|| //edi Cash Advance
	 (pobTran->srTRTRec.TransactionCode == PRE_COMP)

     	 /*
     	 (pobTran->srTRTRec.TransactionCode == CASH_ADV) ||
     	 (pobTran->srTRTRec.TransactionCode == PRE_COMP)
     	 */
     	 ))
     	{
     		map_set(stOptionalMap, 55);

     	}
     	
    	/* LeeChyi - 13122005: Added in following - START
    		There are 3 kind of offline sales: 
    		1) Online sales above floor limit with response code 01.
    		2) Online sales below floor limit
    		3) Offline sales via the terminal option - OFFLINE
    		Field 55 should be sent out for offlines sales of type 1	 and 2.
    		
    		Hence if it is a EMV transaction of type SALE_OFFLINE, we use inEMVCardDecision to differentiate between type 1, 2 and 3.
    		For type 1 and 2, inEMVCardDecision = EMV_OFFLINE_AUTH
    		But for type 3, inEMVCardDecision = EMV_OFFLINE_AUTH
    	*/
		if((pobTran->srBRec.inChipStatus == EMV_CARD) &&
     		(pobTran->srTRTRec.TransactionCode == SALE_OFFLINE)  && (pobTran->inEMVCardDecision == EMV_OFFLINE_AUTH)
		)
     	{
     		map_set(stOptionalMap, 55);
     	}

		if((pobTran->srBRec.inChipStatus == IMAM_CHIP_TAP_CARD) && 
		   ((pobTran->srTRTRec.TransactionCode == SALE_OFFLINE) || (pobTran->srTRTRec.TransactionCode == SALE))
		){
     		map_set(stOptionalMap, 55);
	//		map_set(stOptionalMap, 23);
			if (fImamCTLTag5F34Exist == VS_FALSE) {
				map_reset(stOptionalMap, 23);
				LOG_PRINTFF((0x08L, "DE-23 RESET"));
			}
     	}

     	/* LeeChyi - END */

	if((pobTran->srBRec.inChipStatus == EMV_CARD) &&
     	((pobTran->srTRTRec.TransactionCode == SALE) || 
		(pobTran->srTRTRec.TransactionCode == AUTH_ONLY) || 
		(pobTran->srTRTRec.TransactionCode == IMAM_CARDVER) || 
		(pobTran->srTRTRec.TransactionCode == PRE_AUTH) ||
     	(pobTran->srTRTRec.TransactionCode == CITI_EPP_SALE) ))  //spqalog008
     	{
     		//map_set(stOptionalMap, 23);// spqa jrd 05212005
			if (fImamTag5F34Exist == VS_FALSE) { 
				map_reset(stOptionalMap, 23);
				LOG_PRINTFF((0x08L, "DE-23 RESET"));
			}
     	}
	#endif /* VXEMVAPP */
    }

    if ( ((pobTran->srBRec.inCode==SALE) && (pobTran->srTRTRec.TransactionCode==SALE)) ||
		 ((pobTran->srBRec.inCode==AUTH_ONLY) && (pobTran->srTRTRec.TransactionCode==AUTH_ONLY)) ||
		 ((pobTran->srBRec.inCode==IMAM_CARDVER) && (pobTran->srTRTRec.TransactionCode==IMAM_CARDVER)) ||
		 ((pobTran->srBRec.inCode==PRE_AUTH) && (pobTran->srTRTRec.TransactionCode==PRE_AUTH)) ||
		  ((pobTran->srBRec.inCode==CITI_EPP_CASHBACK) && (pobTran->srTRTRec.TransactionCode==CITI_EPP_CASHBACK)) //edi - Cash Advance
	   ) {
		if ((pobTran->srBKey.fVoided == VS_FALSE) && (pobTran->srBRec.inCode != BATCH_UPLOAD)) {
			if ( ((pobTran->srBRec.fManual==VS_TRUE) && (fGetImamManual4DBC())) ||
				 ((pobTran->srBRec.fManual==VS_FALSE) && (fGetImamSwipe4DBC()))
				){
					map_set(stOptionalMap, 55);
			}
		}
	}

    if ( ((pobTran->srBRec.inCode==SALE) && (pobTran->srTRTRec.TransactionCode==SALE)) ||
		 ((pobTran->srBRec.inCode==REFUND) && (pobTran->srTRTRec.TransactionCode==REFUND)) ||
		 ((pobTran->srBRec.inCode==IMAM_PREAUTH) && (pobTran->srTRTRec.TransactionCode==IMAM_PREAUTH)) ||
		 ((pobTran->srBRec.inCode==IMAM_PREAUTH_CANCEL) && (pobTran->srTRTRec.TransactionCode==IMAM_PREAUTH_CANCEL)) ||
		 ((pobTran->srBRec.inCode==IMAM_PRECOMP) && (pobTran->srTRTRec.TransactionCode==IMAM_PRECOMP)) ||
		 ((pobTran->srBRec.inCode==IMAM_PRECOMP_CANCEL) && (pobTran->srTRTRec.TransactionCode==IMAM_PRECOMP_CANCEL)) ||
		 ((pobTran->srBRec.inCode==DEBIT_BAL_INQ) && (pobTran->srTRTRec.TransactionCode==DEBIT_BAL_INQ)) 
	   ) {
		if ((pobTran->srBKey.fVoided == VS_FALSE) && 
			(pobTran->srBRec.inCode != BATCH_UPLOAD) &&
			(pobTran->srBRec.fManual == VS_FALSE) &&
			(pobTran->srBRec.inTranCardType == DEBIT_CARD)
		   ){
			LOG_PRINTFF((0x08L, "F52 SET"));
			map_set(stMap8583, 52);
		} 
	}
	if ((pobTran->srTRTRec.TransactionCode==VOID) && (pobTran->srBRec.inTranCardType == DEBIT_CARD)) {
		if (fGetImamVoidSwipePin()==1) {
			map_set(stMap8583, 52);
		} else {
			map_reset(stMap8583, 52);
		}
	}	
    if (pobTran->srBRec.inTranCardType != DEBIT_CARD){  
		map_reset(stMap8583, 52); 
	}

	if (ImamActiveMenu->inDataID == 11 && pobTran->srTRTRec.TransactionCode == SALE){
		srISO.pszField03[0] = 0x42;
		map_set(stOptionalMap, 48);
	}

	if ((pobTran->srTRTRec.TransactionCode==SALE) &&  // for SSP
		(pobTran->srBRec.inInstallments >= 2) && 
		(pobTran->srBRec.inInstallments <= 99) && 
		(pobTran->srBRec.inPlan >= 1) &&(pobTran->srBRec.inPlan <= 3)) {
		map_set(stOptionalMap, 61);
	}

	if ((pobTran->srTRTRec.TransactionCode==SALE) &&  // for Online Redemption
		(pobTran->srBRec.inInstallments >= 1) && 
		(pobTran->srBRec.inPlan >= 4)) {
		map_set(stOptionalMap, 61);
	}

	if (pobTran->srTRTRec.TransactionCode == POINT_BAL_INQ) {  // for Online Redemption
		map_set(stOptionalMap, 61);
	}

	if (fGetImamAirlineTrx() && (pobTran->srTRTRec.TransactionCode==SALE)) {  // for Airline
		map_set(stOptionalMap, 54);
		// ketut 
		//map_set(stOptionalMap, 63);
	}

	if (fGetImamPrivateLabel() && (pobTran->srTRTRec.TransactionCode==SALE)) {  // for PRIVATE LABEL BNI/LIPPO
		map_set(stOptionalMap, 63);
	}

	if ((inGetCVV_II() == CVV2_CARD_EITHER) && (pobTran->srBRec.fManual == VS_TRUE) && (pobTran->srTRTRec.TransactionCode==SALE)) {  // for CVV2
		map_set(stOptionalMap, 63);
	}

	if (pobTran->srBRec.inTranCardType == DEBIT_CARD && pobTran->srTRTRec.TransactionCode==REFUND) {
		map_set(stOptionalMap, 38);
	}

	if (pobTran->srTRTRec.TransactionCode == IMAM_ECHO || pobTran->srTRTRec.TransactionCode == IMAM_LOGON) { 
		map_reset(stOptionalMap, 45);
		memset(stOptionalMap, 0, BIT_MAP_SIZE);
		LOG_PRINTFF((0x08L, "IMAM_ECHO or IMAM_LOGON"));
	}

	if ((fGetImamMacField()) && (pobTran->srTRTRec.TransactionCode!=IMAM_LOGON)) {
		LOG_PRINTFF((0x08L, "F64 SET"));
		map_set(stMap8583, 64);     //stOptionalMap not work
	}
#ifdef IMAM_CR2
	if (pobTran->srTRTRec.TransactionCode==VOID){
		map_set(stMap8583, 12); 
		map_set(stMap8583, 13); 
	}
#endif
/*
	if (inEnableWaveReader()) {
		if (pobTran->srTRTRec.TransactionCode==SALE){
			map_set(stOptionalMap, 63);
		}
	}
*/
    vdGetCPACTPDU((char *) tpdu);
    return(VS_SUCCESS);
}



void vdInitializeCITI( PACKET_OBJECT *pobPacket )
{
    pobPacket->inInitialize = (PFI_VD) inCITIInit;
    pobPacket->inAnalyse = (PFI_VD) inCITIPIPAnalyse;
    pobPacket->inDeinitialize = (PFI_VD) inCPACPIPDeinitialize;
}

/*********************************************************************************************
* @func int | inSendReceiveCITI|
* Creates Host structure and the transaction code then calls pip_trans() which is the
* PIP engine function that controls the packet building and communication. Once the
* pip_trans returns, either the error is processed or advice transactions are sent and
* the response is processed.
*
* Modified - (Loxbit Thailand to incorporate reversal updations with current STAN
* 23/Feb/2002 -Loxbit Bangkok
*
* @parm PROTOCOL_OBJECT * |pobProtocol |
*       Protocol object
*
* @parm PACKET_OBJECT * |pobPacket |
*       Packet object
*
* @rdesc Returns the PIP Engine error code.
* @flag int | VS_ERR
* @flag int | VS_SUCCESS
* @end
* @end
**********************************************************************************************/

int inSendReceiveCITI(PROTOCOL_OBJECT* pobProtocol,PACKET_OBJECT* pobPacket) {
    char szLog[60 + 1];
    int inRetVal;
    short shTransCode,
    shPIPTransCode;
    field_struct* fld_2;
	char szTempBuffer[22 + 1];
	char szTagIndicator[2 + 1];
       char szEPPMonDue[13 + 1];
       char szEPPInterestRate[7 + 1];

    TRANSACTION_OBJECT* pobTran;
    //  HOST_8583_DATA  my_host_struct;
    //  char szRevFileName[FILENAME_SIZE +1];
    /**/pdebug(("--inSendReceiveCPACPIP--"));/**/
      memset(szTagIndicator, 0x00, sizeof(szTagIndicator));
      memset(szEPPMonDue, 0x00, sizeof(szEPPMonDue));
      memset(szEPPInterestRate, 0x00, sizeof(szEPPInterestRate));
    pobTran = (TRANSACTION_OBJECT *) pobPacket->Transaction;
    pobPacket->inError = 0;                                                 /* Initialize error */
#ifdef UPDATE_REV_STAN    /*   Saritha_b1 changed from TLFB to UPDATE_REV_STAN */

    //inCPACModifyReversal (pobTran, psrHostData);

    /*  Saritha_b1..........Start........Fix for Comm Error during Tip Adjust..... */

    if (!(pobTran->srTRTRec.Offline))
        if (fGetCPACStanInc()) // Making it host specific
            inCPACModifyReversal(pobTran);  // Update the reversal with the current STAN

    /*  Saritha_b1..........End........Fix for Comm Error during Tip Adjust..... */

    pobTran->srBRec.lnSTAN = lnGetSTAN(); // gets the STAN from the MHT, latest STAN

#endif /* UPDATE_REV_STAN       Saritha_b1 changed from TLFB_LOXBIT  to UPDATE_REV_STAN */

    if ((psrHostData = psrCreateHostData()) == (HOST_8583_DATA *) NULL_CH) {
        vdFreeHostData(psrHostData);
        vdFreeVariantTables();
        vdSGErrorMessage(NO_MEM_ERR_MSG);
        ACTIVITY_LOG("No Memory: SendReceiveCPAC 00");
        return(VS_ERR);
    }

    if ((psrHostData->c8583_data = psrCreateCommData(pobTran, CPAC_SEND_SIZE, VS_TRUE)) == (COMM_8583_DATA *) NULL_CH) {
        vdSGErrorMessage(NO_MEM_ERR_MSG);
        ACTIVITY_LOG("No Memory: SendReceiveCPAC 01");
		//Start : Alona_G1 03082005 To fix the AMEX reversal problem where 16 digit PAN was going in reversal request for AMEX
		while( psrHostData->c8583_data->p_fld_table->field_num != 2)
			psrHostData->c8583_data->p_fld_table++;
		fld_2 = psrHostData->c8583_data->p_fld_table;
		memset(fld_2->reference, 0x00, fld_2->var_sz);
		//End Alona_G1
        vdFreeISO8583Data(psrHostData);
	 vdFreeHostData(psrHostData);
	 vdFreeVariantTables();
        return(VS_ERR);
    }

	psrHostData->c8583_data->transceiver = inImamTxRx8583;  //
#ifdef MODEM
	if (inGetUCLCommLink()==0) {  // to get resp timeout
		MODEM_OBJECT *obModem;
		obModem = (MODEM_OBJECT *)obCommunication.Data;
		psrHostData->c8583_data->comm_timeout         = obModem->shGetRespTimeOut(obModem->srCPT);  // for Response TimeOut
		psrHostData->c8583_data->wait_for_carrier     = obModem->shGetCarrierTimeOut(obModem->srCPT); // for Carier TimeOut
	}
#endif

    ((VALIDATION_STRUCT *) (psrHostData->c8583_data->v_parms))->comm_struct = psrHostData->c8583_data;
    /* Added for Custom base resp validation CPAC_VALID */

    psrHostData->c8583_data->validation = (PFI_PVOID_INT) inCPACBaseRespValidation;
    /* Added for Custom base resp validation CPAC_VALID */
    /* Set the reversal flag ON based on the transaction type */

    psrHostData->reverse_flag = (unsigned char) fGetReversal(pobTran);
    /*  vdGetReversalFileName((char *)stRevFileName, inGetCDTHostIndex()); */

    if (pobTran->srBRec.inCode == TC_UPLOAD) //jrd 05282005
    	psrHostData->reverse_flag = 0;

    vdGetReversalFileName((char *) stRevFileName, inGetHostHandle());
    shTransCode = shVerifyCPACTransType(pobTran);                               /* Store our update GGCode value so that set_trans_fields() can use it */
    inStoreTranFlexiData(pobTran, AMEX_PIP_TRANS_CODE, (unsigned char *) &shTransCode, 2);

    if ((shPIPTransCode = shLoadPIPTransCode(shTransCode)) == VS_ERR) {
		//Start : Alona_G1 03082005 To fix the AMEX reversal problem where 16 digit PAN was going in reversal request for AMEX
		while( psrHostData->c8583_data->p_fld_table->field_num != 2)
			psrHostData->c8583_data->p_fld_table++;
		fld_2 = psrHostData->c8583_data->p_fld_table;
		memset(fld_2->reference, 0x00, fld_2->var_sz);
		//End Alona_G1
        vdFreeISO8583Data(psrHostData);
	 vdFreeHostData(psrHostData);
	 vdFreeVariantTables();
        ACTIVITY_LOG("No Memory: SendReceiveCPAC 02");
        return (VS_ERR);
    }

    if (inGGCode() == REFUND && fGetOffline(pobTran))
        shPIPTransCode = (int) A_REFUND_OFFLINE ;


    //for making REFUND go as offline for AMEX


    /* Higher byte of inPIPTransCode contains index into the BitMap file.
                Higher byte of inPIPTransCode contains index into the BitMap file.
                Lower byte of inPIPTransCode contains the transaction type for Pip
                Processing */


    errno = 0;
#ifdef CITI_IND
    //  if (inPIPTransCode == 8213) inPIPTransCode = 3604;  //leo_aug700 added !!
#endif /* CITI_IND*/                                                            // To make Void of a Refund acceptable to pip_trans!!
    /* if (inPIPTransCode == 0x0e14) inPIPTransCode = 0x0d14;   */

    inRetVal = pip_trans((int) shPIPTransCode, psrHostData);

    /* pdebug(("pip_trans Ret=%d",inRetVal));*/
      // pdebug(("errno=%d fn_8583=%d",errno, fn_8583));
	//LOG_PRINTFF((0x8L, "errno=%d fn_8583=%d",errno, fn_8583));

     LOG_PRINTFF((0x8L, "pIP=%d",inRetVal));
	 LOG_PRINTFF((0x8L, "errno=%d",errno));

	/*if((!strcmp((char *) srISO.pszField39, "00")) && (pobTran->srBRec.inChipStatus == EMV_CARD))*/
	/* jrd force the value of pip_trans since the host is sending a wrong packet for CHIP Sale*/
	/*if((inRetVal == -53) && (pobTran->srBRec.inChipStatus == EMV_CARD) )
	{
		inRetVal = PIP_APPROVAL;
		//strcpy((char *)srISO.pszField39,"00");
		LOG_PRINTFF((0x8L, "PPIPP=%d",inRetVal));

	}*/
//	edi - oi penting nih
////////////////////////////////////////
// sementara
if(pobTran->srBRec.inChipStatus == EMV_CARD){
	if((inRetVal == AMEX_VOICE_AUTH) && ((inGGCode() == SALE)||(inGGCode()== REFUND) ))
		{
			LOG_PRINTF(("AMEX VOICE AUTH**********"));
			inRetVal = PIP_APPROVAL;
			LOG_PRINTFF((0x8L, "PPIPP=%d",inRetVal));

		}

} 

#ifdef VXEMVAPP
    	vdSetEMVOnlineCondition(pobTran, inRetVal);
#endif


    //if( (inRetVal != PIP_APPROVAL)&&((inRetVal != AMEX_VOICE_AUTH)||(pobTran->srBRec.inChipStatus!=EMV_CARD))) {
    
    /* LeeChyi - 14122005: Modified - START*/
 	/* Commented off following line and added in next line */
 	/* For EMV transactions, if inRetVal != PIP_APPROVAL but inRetVal = HOST_ERROR, then we will not exit out from this function. 
 		We should proceed on such the second gen ac is processed thought second gen ac will return AAC. */
 	//if( inRetVal != PIP_APPROVAL) {
    if( (inRetVal != PIP_APPROVAL) && 
		( (inRetVal != HOST_ERROR) || (pobTran->srBRec.inChipStatus != EMV_CARD)) 
		) { //SWIPE: All Cases, EMV: All but HOST_ERROR ==> so ALL REFERRAL will be done by inImamReferralSendReceive
	/* LeeChyi - END */
	
        vdCPACError(pobProtocol, pobPacket, inRetVal);
        LOG_PRINTFF((0x8L, "NOT PIP APPROVAL"));
        sprintf(szLog, "%s  %d ", "Pip Trans:inSendReceiveCPAC03", errno);
        ACTIVITY_LOG(szLog);

		//Start...To fix the AMEX reversal problem where 16 digit PAN was going in reversal request for AMEX
		while( psrHostData->c8583_data->p_fld_table->field_num != 2)
			psrHostData->c8583_data->p_fld_table++;
		fld_2 = psrHostData->c8583_data->p_fld_table;
		memset(fld_2->reference, 0x00, fld_2->var_sz);
		//End...To fix the AMEX reversal problem where 16 digit PAN was going in reversal request for AMEX

        vdFreeISO8583Data(psrHostData);
		vdFreeHostData(psrHostData);
		vdFreeVariantTables();
        return(pobPacket->inError);
    }
		
    //inRetVal = HOST_ERROR;
    //vdCPACError(pobProtocol, pobPacket, inRetVal);
	if((pobTran->srTRTRec.TransactionCode == CITI_EPP_SALE ))
		{
                memset(szTempBuffer, 0x00, sizeof(szTempBuffer));
                strcpy(szTempBuffer, (char *)srISO.pszField48);
                memcpy(szTagIndicator, &(szTempBuffer[0]), 2);
                memcpy(szEPPMonDue, &(szTempBuffer[2]),13);
                memcpy(szEPPInterestRate, &(szTempBuffer[15]), 7);
                inStoreBatchFieldData(&pobTran->srBRec, CITI_EPP_MONTHLY_DUE, (unsigned char *)szEPPMonDue, 13);
                inStoreBatchFieldData(&pobTran->srBRec, CITI_EPP_INTEREST_RATE, (unsigned char *)szEPPInterestRate, 7);
		}

    if (pobTran->srBRec.inCode == PRE_AUTH && pobTran->srBKey.fOffline) {
        vdCPACDeleteTabAdvice(psrHostData);
        vdSetCPACOpenTabOffline(&pobTran->srBRec, VS_TRUE);
    }

	//Start...To fix the AMEX reversal problem where 16 digit PAN was going in reversal request for AMEX
		while( psrHostData->c8583_data->p_fld_table->field_num != 2)
			psrHostData->c8583_data->p_fld_table++;
		fld_2 = psrHostData->c8583_data->p_fld_table;
		memset(fld_2->reference, 0x00, fld_2->var_sz);
	//End...To fix the AMEX reversal problem where 16 digit PAN was going in reversal request for AMEX

    vdFreeISO8583Data(psrHostData);
    return(VS_SUCCESS);
}

int inImamReferralSendReceive(PROTOCOL_OBJECT* pobProtocol,PACKET_OBJECT* pobPacket) 
{
    int inRetVal;
    short shTransCode, shPIPTransCode;
    TRANSACTION_OBJECT* pobTran;

	pobTran = (TRANSACTION_OBJECT *) pobPacket->Transaction;
    pobPacket->inError = 0;                                                 /* Initialize error */

	pobTran->srTRTRec.Offline = VS_TRUE;
	pobTran->srBKey.fOffline = VS_TRUE;
	if (inGGCode() == SALE_OFFLINE){
		pobTran->srTRTRec.TransactionCode = SALE_OFFLINE;
	}

    shTransCode = shVerifyCPACTransType(pobTran);                               /* Store our update GGCode value so that set_trans_fields() can use it */
    inStoreTranFlexiData(pobTran, AMEX_PIP_TRANS_CODE, (unsigned char *) &shTransCode, 2);
    if ((shPIPTransCode = shLoadPIPTransCode(shTransCode)) == VS_ERR) return (VS_ERR);
	errno = 0;
	vdInitializeValidationStruct(pobTran, psrHostData->c8583_data->v_parms); //LIEM: MUST ADD THIS for OFFLINE SETTLE LATER

	inRetVal = pip_trans((int) shPIPTransCode, psrHostData);

    if (inRetVal != PIP_APPROVAL) {
	    LOG_PRINTFF((0x8L, "NOT PIP APPROVAL ON REFERRAL"));
        return(pobPacket->inError);
    }
		
    return(VS_SUCCESS);
}


/*********************************************************************************************
* @func void | vdLoadField23|
* Load the Card Account Number - ISO Field # 23
*
* @parm TRANSACTION_OBJECT * | pobTran |
*       This is the transaction object.
*
* @end
**********************************************************************************************/

int inImamGetTag(unsigned char *szTag, int *inTagLen, unsigned char *szHexBuff, unsigned char *szValue)
{
	unsigned char szTagFound[10];
	unsigned char szTagFoundValue[256];
	int inTagFoundLen = 0;	
	int i = 0;
	for (i=0; i<255 ;i++){
		memset(szTagFound, 0x00, sizeof(szTagFound));
		memset(szTagFoundValue, 0x00, sizeof(szTagFoundValue));
		if ((szHexBuff[i] & 0x0F) == 0x0F){
			memcpy(szTagFound, &szHexBuff[i], 2);
			i = i+2;
			inTagFoundLen = szHexBuff[i];
			i = i+1;
			memcpy(szTagFoundValue, &szHexBuff[i], inTagFoundLen); 
			i = i+inTagFoundLen;
			i--;
		} else if (szHexBuff[i] != 0x00){
			memcpy(szTagFound, &szHexBuff[i], 1);
			i = i+1;
			inTagFoundLen = szHexBuff[i];
			i = i+1;
			memcpy(szTagFoundValue, &szHexBuff[i], inTagFoundLen); 
			i = i+inTagFoundLen;
			i--;
		} else {
			return 0;
		}
		LOG_PRINT_HEX(szTagFound, 2);
		LOG_PRINT_HEX(szTagFoundValue, inTagFoundLen);
		if (!memcmp(szTagFound, szTag, *inTagLen)){
			memcpy(szValue, szTagFoundValue, inTagFoundLen); 
			*inTagLen = inTagFoundLen;
			return 1;
		}
	}	
	return 0;
}



void vdLoadCITIEMVField23(TRANSACTION_OBJECT* pobTran) {

	unsigned char bTagOutput[3];
  	unsigned short usLength;
 	int inTotalLength = 0, testlength = 0, testlength3 = 0;
 	unsigned char szTextBuff[10+1];
 	unsigned char szHexBuff[10+1];

	if((pobTran->srBRec.inChipStatus == IMAM_CHIP_TAP_CARD) && 
	   ((pobTran->srTRTRec.TransactionCode == SALE_OFFLINE) || (pobTran->srTRTRec.TransactionCode == SALE))
	){
		unsigned char szChipData[256];
		unsigned char szTag5F34[10];
		int inTagLen = 2;
		vdImamGetCTLData(&pobTran->srBRec, szChipData);
		if (inImamGetTag((unsigned char *)"\x5F\x34", &inTagLen, &szChipData[1], szTag5F34)){
			inTotalLength = szTag5F34[0];	
			sprintf((char *)szTextBuff,"%02d", 0);
 			memcpy(szEMVField23,szTextBuff, 2);
			SVC_HEX_2_DSP((char *)szTag5F34, (char *)szHexBuff,1);
			memcpy(&szEMVField23[2],szHexBuff, 2);
		}		
		LOG_PRINTFF((0x08L, "szEMVField23 = [%s]", szEMVField23));
		return;
   	}

 	memset(szEMVField23, NULL_CH, sizeof(szEMVField23));
 	memset(bTagOutput, 0x00, sizeof(bTagOutput));
  	inCITIBuildEMVHostData23(pobTran,(BYTE *)bTagOutput, &usLength);
	inTotalLength = usLength;
	sprintf((char *)szTextBuff,"%02d", 0);
 	memcpy(szEMVField23,szTextBuff, 2);
	SVC_HEX_2_DSP((char *)bTagOutput, (char *)szHexBuff,1);
	memcpy(&szEMVField23[2],szHexBuff, 2);
	LOG_PRINTFF((0x08L, "szEMVField23 = [%s]", szEMVField23));
	//szEMVField23[0]='0';
	//szEMVField23[1]='0';
	//szEMVField23[2]='0';
	//szEMVField23[3]='0';
	//szEMVField23[4]='\0';

}


int inCITIBuildEMVHostData23(TRANSACTION_OBJECT *pobTran,unsigned char *pbtBuff, unsigned short *pusLen)///ivan
{
	int inOffset = 0;
 	inOffset += inCITIAddDataToEMVPacket23(TAG_5F34_APPL_PAN_SEQNUM, &pbtBuff[inOffset]);
 	*pusLen = (unsigned short)inOffset;
 	return(VS_SUCCESS);
}

int inCITIAddDataToEMVPacket23(unsigned short usTag, unsigned char *pbtPackBuff)
{
	unsigned short usLen;
	BYTE btTmp[128];
	int  offset = 0;
	char buff[256];
	memset(buff, 0x00, sizeof(buff));

	LOG_PRINTFF((0x08L, "--inCITIAddDataToEMVPacket23--"));
	if (usEMVGetTLVFromColxn(usTag, btTmp, &usLen) != EMV_SUCCESS)
		return(0);	// Do does not exist so nothing added to packet

	if (usLen<128) hex_2_asc((BYTE *)buff, btTmp, usLen);
	LOG_PRINTFF((0x08L, "TAG(0x%X): EMVGetTLV[??? = %s]", usTag, buff));
	
	memcpy(pbtPackBuff + offset, btTmp, usLen);

	return(offset + usLen);	// Return number of bytes added to buffer
}

/*********************************************************************************************
* @func void | vdCITILoadField35 |
* Load Track 2 data - ISO Field # 35
*
* @parm TRANSACTION_OBJECT * | pobTran |
*       This is the transaction object.
*
* @end
**********************************************************************************************/

void vdCITILoadField35(TRANSACTION_OBJECT* pobTran) {
//spqalog092
/* // : Disable this
	char szT2[TRACK2_SIZE +1];
	char szT2buf[TRACK2_SIZE +1];
	if (strlen(pobTran->srBRec.szPAN) % 2 == 1)
	{
		memset(szT2, 0x00, sizeof(szT2));
		memset(szT2buf, 0x00, sizeof(szT2buf));
		strcpy(szT2buf,pobTran->srBRec.stT2Data);
		strcpy(szT2,pobTran->srBRec.szPAN);
		strcat(szT2,"?");
		strcat(szT2,&szT2buf[strlen(pobTran->srBRec.szPAN)]);
		memset(pobTran->srBRec.stT2Data, 0x00, sizeof(pobTran->srBRec.stT2Data));
		strcpy(pobTran->srBRec.stT2Data,szT2);
	}
*/
    memcpy((char *) srISO.pszField35, pobTran->srBRec.stT2Data, TRACK2_SIZE);
}

/*********************************************************************************************
* @func void | vdLoadCPACField48 |
* Load Merchant ID - ISO Field # 48
*
* @parm TRANSACTION_OBJECT * | pobTran |
*       This is the transaction object.
*
* @end
**********************************************************************************************/
void vdLoadCITIField48(TRANSACTION_OBJECT *pobTran)
{
	 //sprintf((char *)srISO.pszField48, "%s", );//1.4 LENIN

	char szMyScratch1[30+1];
	char szMyScratch2[10+1];
	char szMyScratch3[10+1];

	if (ImamActiveMenu->inDataID == 11 && pobTran->srTRTRec.TransactionCode == SALE){
		memset((char *)srISO.pszField48, 0x00, sizeof(srISO.pszField48));
		strcpy((char *)srISO.pszField48, "9940000");
		strncat((char *)srISO.pszField48, szMifareData, 28);
		strncat((char *)srISO.pszField48, "            ", 9);
		strncat((char *)srISO.pszField48, &szMifareData[32], 12);
	}

	if(pobTran->srBRec.inCode  == BATCH_UPLOAD && pobTran->srBRec.inOrgCode == CITI_EPP_SALE)
	 {
               memset(szMyScratch1, 0x00, sizeof(szMyScratch1));
		 inGetBatchFieldData(&pobTran->srBRec, CITI_EPP_TENOR, (unsigned char*)szMyScratch1, 5);
		 memset(szMyScratch2, 0x00, sizeof(szMyScratch2));
		 inGetBatchFieldData(&pobTran->srBRec, CITI_REG_RATE, (unsigned char*)szMyScratch2, 2);
               memset(szMyScratch3, 0x00, sizeof(szMyScratch3));
	        inGetBatchFieldData(&pobTran->srBRec, CITI_EPP_INTEREST_RATE, (unsigned char*)szMyScratch3, 7);
		 strcat(szMyScratch1, szMyScratch3);
		 strcat(szMyScratch1, szMyScratch2);
               strcpy((char*)srISO.pszField48, (char*)szMyScratch1);
		 return;
	 }
	 if((pobTran->srTRTRec.TransactionCode == CITI_EPP_SALE ))
	{
		 memset(szMyScratch1, 0x00, sizeof(szMyScratch1));
		 inGetBatchFieldData(&pobTran->srBRec, CITI_EPP_TENOR, (unsigned char*)szMyScratch1, 5);
		 memset(szMyScratch2, 0x00, sizeof(szMyScratch2));
		 inGetBatchFieldData(&pobTran->srBRec, CITI_REG_RATE, (unsigned char*)szMyScratch2, 2);
		 strcat(szMyScratch1,szMyScratch2);
		 strcpy((char*)srISO.pszField48, (char*)szMyScratch1);
		 return;
	}

	// return;
}

/*********************************************************************************************
* @func void | vdLoadCITIField54 |
* Load the additional amount field - ISO Field # 54
*
* @parm TRANSACTION_OBJECT * | pobTran |
*       This is the transaction object.
*
* @end

**********************************************************************************************/
void vdLoadCITIField54(TRANSACTION_OBJECT* pobTran) 
{
    //char    szScratch[25];   CPAC_LINT_REMOVED
    VS_BOOL fIncludeTipField = VS_FALSE;

    if(pobTran->srTRTRec.TransactionCode == CITI_EPP_CASHBACK) {
		memcpy(srISO.pszField54, srISO.pszField04, ISO_AMT_SIZE);
    } else {
   	 /** /pdebug (("---in Load Field 54---"));*/
    	/*    if (pobTran->srBKey.fVoided   || ( atol ((char *)srISO.pszField54) == 0L)) CPAC_UNBKL removed & added the following */
    	if (pobTran->srBKey.fVoided || (pobTran->srBRec.lnTipAmount == 0L)) {
       		map_reset(stOptionalMap, 54);
		} else {
        	if ((pobTran->fTipAdjust) && !pobTran->srBKey.fUploaded && pobTran->srBRec.fTipEntered) {
           	 	fIncludeTipField = VS_TRUE;
			}
			{ // Amount - Currency Adjust
				if (inGetCurrencyIdx()) {
					sprintf((char *) srISO.pszField54, SUBSTITUTE_LD, pobTran->srBRec.lnTipAmount);
				} else {
					sprintf((char *) srISO.pszField54, "%ld00", pobTran->srBRec.lnTipAmount);
				}
    		}
		}
	}

    if (atol((char *) srISO.pszField54) == 0L && !fIncludeTipField)
        map_reset(stOptionalMap, 54);
    else
        pad((char *) srISO.pszField54, (char *) srISO.pszField54, '0', ISO_AMT_SIZE, RIGHT);
}



/*********************************************************************************************
* @func int | inCITIInit |
*       Function for the PACKET_OBJECT structure. Initializes the variant structures
*       and calls all the required overload functions
*
* @parm PACKET_OBJECT * | obPacket
*       Packet object
*
* @rdesc return values.
* @flag int | VS_SUCCESS or VS_ERR
* @end
**********************************************************************************************/

int inCITIInit(PACKET_OBJECT* pobPacket) {

	#ifdef VXEMVAPP

		srFieldEMV55ISOFDT.field_num = 55;
		srFieldEMV55ISOFDT.packet_sz = EMV_FIELD55_SIZE;
		srFieldEMV55ISOFDT.convert_idx = AV3_AV3;
		srFieldEMV55ISOFDT.reference = szEMVField55;
		srFieldEMV55ISOFDT.var_sz = EMV_FIELD55_SIZE + 1;

		vdOverLoadISOFDT(FIELD55_POSITION, &srFieldEMV55ISOFDT );

		//jrd 05212995
		srFieldEMV23ISOFDT.field_num = 23;
		srFieldEMV23ISOFDT.packet_sz = EMV_FIELD23_SIZE;
		srFieldEMV23ISOFDT.convert_idx = BCD_STR;
		srFieldEMV23ISOFDT.reference = szEMVField23;
		srFieldEMV23ISOFDT.var_sz = EMV_FIELD23_SIZE + 1;

		vdOverLoadISOFDT(FIELD23_POSITION, &srFieldEMV23ISOFDT );

    #endif /* VXEMVAPP */

	if (inCPACCreateVariantStruct60() == VS_ERR) {
        vdFree((char *) psrVariant60);
        vdSGErrorMessage(NO_MEM_ERR_MSG);
        //ACTIVITY_LOG("Insufficient Memory 02");
        return(VS_ERR);
    }

    if (inCPACCreateVariantStruct63() == VS_ERR) {  //LIEM : change to CPAC to avoid confusing
              vdFreeVariantTables();
        vdSGErrorMessage(NO_MEM_ERR_MSG);
        //ACTIVITY_LOG("Insufficient Memory 03");
        return(VS_ERR);
    }

    vdOverLoadLoadDataFuncs(srCITILoadDataFuncs);

    inOverloadFieldID(INIT_VALIDATION_STRUCT, (PFI_TO) inInitializeCPACValidationStruct);
    inOverloadFieldID(MODIFY_BATCH_REC, inModifyCPACBatchRec);
    inOverloadFieldID(SET_TRANS_FIELDS, (PFI_TO) inSetCITITransFields);

    inOverloadFieldID(UPDATE_REVERSAL, (PFI_TO) inUpdateCPACReversal);   // CPAC_UNBKL added
    memset(srISO.pszField37, 0, sizeof(srISO.pszField37));  // CPAC_UNBKL added
    memset(srISO.pszField38, 0, sizeof(srISO.pszField38));  // CPAC_UNBKL added


    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func int | inCITIPIPAnalyse |
*       Function for the PACKET_OBJECT structure. Stores the response message and uploads
*       the advices
*
* @parm PACKET_OBJECT * | obPacket
*       Packet object
*
* @rdesc return values.
* @flag int | VS_SUCCESS or VS_ERR
* @end
**********************************************************************************************/

int inCITIPIPAnalyse(PACKET_OBJECT* pobPacket) 
{
    char szAuthCode[AUTH_CODE_SIZE + 1];
    char szStatusMessage[MESSAGE_SIZE + 1];
    unsigned char szReqMti[MTI_SIZE];   /* CPAC_UNBKL added */
    unsigned char szDummy[50];          /* CPAC_UNBKL added */
    TRANSACTION_OBJECT* pobTran;

    /** /pdebug(("--inCPACPIPAnalyse--"));*/
    pobTran = (TRANSACTION_OBJECT *) pobPacket->Transaction;

    /* get data from field table fields and put in GDS this needs to happen before inUploadAdvices() */
    inPFRStateStoreAll(CPAC_PFR_ANALYSE_BEGIN, pobTran, 1, 1);

    if (!fGetOffline(pobTran)) {
        // CPAC_UNBKL added {
        inLoadBitmap(((TRANSACTION_OBJECT *) pobPacket->Transaction)->srBRec.inCode, szReqMti, szDummy, szDummy);
        szReqMti[1] += 0x10;
        if (memcmp(szReqMti, Mti, MTI_SIZE) != 0) {
            ACTIVITY_LOG("MTI mismatch!");
            return(VS_ERR);
        }
        // CPAC_UNBKL added }
        strlcpy(pobTran->srBRec.szAuthCode, (char *) srISO.pszField38, FIELD38_SIZE); /* Auth Code to Batch */
        strlcpy(pobTran->srBRec.szRespCode, (char *) srISO.pszField39, FIELD39_SIZE); /* Response Code to Batch */
        /* Host date & time to pobTran */
		memset(pobTran->srBRec.szTime, 0x00, sizeof(pobTran->srBRec.szTime));
		memset(pobTran->srBRec.szDate, 0x00, sizeof(pobTran->srBRec.szDate));
        strlcpy(pobTran->srBRec.szTime, (char *) srISO.pszField12, TIME_SIZE);
        strlcpy(pobTran->srBRec.szDate, (char *) srISO.pszField13, DATE_SIZE);
		if ( (!strcmp(pobTran->srBRec.szRespCode, "00")) && 
			 (strlen(pobTran->srBRec.szTime)>=4) && 
			 (strlen(pobTran->srBRec.szDate)>=4)
			) { //LIEM: Add some condition
			vdCPACSyncHostDateTime(pobTran->srBRec.szDate, pobTran->srBRec.szTime);
		}
    }

#ifdef VXEMVAPP
	// added by jhia jrd
	if (pobTran->srBRec.inChipStatus==EMV_CARD && !fGetOffline(pobTran)) {
		usEMVUpdateTLVInCollxn(TAG_8A_AUTH_RESP_CODE , (byte *)srISO.pszField39, 2);
		LOG_PRINTFF((0x08L, "TAG(0x%X): EMVUpdateTLV[TAG_8A_AUTH_RESP_CODE = %s]", TAG_8A_AUTH_RESP_CODE, srISO.pszField39));
	}

    if ((strcmp(pobTran->srBRec.szRespCode, "00") == 0) ||
       (strcmp(pobTran->srBRec.szRespCode, "10") == 0) ||
       (strcmp(pobTran->srBRec.szRespCode, "11") == 0)) {
		pobTran->srBRec.inTransactionResult = AUTHORIZED;
        vdSGErrorMessage(0L);
        vdSGRespMsg("Approval");
	} else if ((strcmp(pobTran->srBRec.szRespCode, "01") == 0) || (strcmp(pobTran->srBRec.szRespCode, "02") == 0)) {
		pobTran->inEMVCardDecision = EMV_VOICE_REFERRAL;
        pobTran->srBRec.inTransactionResult = HOST_REFERRAL;
        vdSGErrorMessage(0L);
        vdSetCPACRetRefNum(&pobTran->srBRec, srISO.pszField37); //KiaSoon 070206: To print reference number on sales completion.
        vdSGRespMsg("Referral");
    } else if (strcmp(pobTran->srBRec.szRespCode, "05") == 0) {
		/* LeeChyi 14122005: Modified for enhancements: Modified from DECLINED to be HOST_DECLINED */
        //pobTran->srBRec.inTransactionResult = DECLINED;
		pobTran->srBRec.inTransactionResult = HOST_DECLINED;
        /* LeeChyi - END */
        vdSGErrorMessage(TRANS_FAIL_ERR_MSG21);
        vdSGRespMsg("Declined");
    } else {
    	pobTran->inOnlineFailed = EMV_COMMS_FAILURE;
        pobTran->srBKey.fOffline = VS_TRUE;
    }
	//inGlobalNumberScripts = createScriptFiles(pobPacket->pchReceiveBuff);
	inGlobalNumberScripts = 0;
	fImamNeedToSendTC = VS_FALSE;
	if (pobTran->srBRec.inChipStatus==EMV_CARD && //KiaSoon 17022006: added in for auth only
	   (pobTran->srBRec.inCode == SALE || pobTran->srBRec.inCode ==IMAM_CARDVER || pobTran->srBRec.inCode ==AUTH_ONLY || pobTran->srBRec.inCode ==PRE_AUTH/*|| LIEM for pobTran->srBRec.inCode ==REFUND */)  && 
	    pobTran->srBRec.inTransactionResult == AUTHORIZED &&
	    pobTran->inEMVCardDecision == EMV_GO_ONLINE) {
		//pobTran->inEMVCardDecision == EMV_OFFLINE_AUTH){
		fImamNeedToSendTC = VS_TRUE;
	}
 #endif

    if ((!fGetOffline(pobTran)) && (pobTran->srBRec.inType != ADMIN_TRAN) && inGetNumAdv()) {
		// CPAC_UNBKL added inGetHDTNumAdv()
		inUploadCPACAdvices(VS_FALSE, pobTran);
	}
    memset(szStatusMessage, 0, sizeof(szStatusMessage));
    //vdGetMessageFromFile(TRANS_APP_MSG, szStatusMessage);
    strlcpy(szAuthCode, pobTran->srBRec.szAuthCode, AUTH_CODE_SIZE);
    vdSGRespMsg(szStatusMessage);
    return(VS_SUCCESS);
}




/*********************************************************************************************
* @func void | vdLoadCITIField63 |
* Load the Private Field 63
*
* @parm TRANSACTION_OBJECT * | pobTran |
*       This is the transaction object.
*
* @end
**********************************************************************************************/

void vdLoadCITIField63 (TRANSACTION_OBJECT *pobTran)
{
ACCUM_REC srHostTotals ;
//ACCUM_TOTALS *psrTotals ;   CPAC_LINT_REMOVED
char    szScratch[30];
    double dbSaleAmount;
double  dbRefundAmount;
long    lnSaleCount;
long    lnRefundCount;

    double dbDebitSaleAmount;
    double dbDebitRefundAmount;
    long lnDebitSaleCount;
    long lnDebitRefundCount;

    /*pdebug(("--vdLoadField63--"));*/

    if ((pobTran->srBRec.inCode==SALE) &&   // for CVV2 Processing
		(pobTran->srTRTRec.TransactionCode==SALE) &&
		((inGetCVV_II() == CVV2_CARD_EITHER) && (pobTran->srBRec.fManual == VS_TRUE))){
		memset((char *)srISO.pszField63, 0x00, sizeof(srISO.pszField63));
		//pobTran->chCVV2PresenceIndicator = CVV2_VALUE_PRESENCE;
		memcpy((char *)srISO.pszField63, "\x00\x10\x00\x08\x31\x36", 6);
		strcpy((char *)&srISO.pszField63[6], "11 "); //check from chCVV2PresenceIndicator
		strcpy((char *)&srISO.pszField63[9], pobTran->szCVV2Value);
		return;
	}
/*
    if ((pobTran->srBRec.inCode==SALE) &&   // TAP
		(pobTran->srTRTRec.TransactionCode==SALE) &&
		(inEnableWaveReader())){
		memset((char *)srISO.pszField63, 0x00, sizeof(srISO.pszField63));
		strcpy((char *)srISO.pszField63, "CL0910");
		return;
   	}
*/
    if ((pobTran->srBRec.inCode==SALE) &&   // for Airline
		(pobTran->srTRTRec.TransactionCode==SALE) &&
		(fGetImamAirlineTrx())){
		memset((char *)srISO.pszField63, 0x00, sizeof(srISO.pszField63));
		if (strlen(pobTran->srBRec.szCustNum)<TICKET_ID_SIZE) 
			strncpy((char *)srISO.pszField63, "0000000000000", TICKET_ID_SIZE - strlen(pobTran->srBRec.szCustNum));
		strcat((char *)srISO.pszField63, pobTran->srBRec.szCustNum);
		return;
   	}

    if ((pobTran->srBRec.inCode==SALE) &&   // for PRIVATE LABEL BNI/LIPPO
		(pobTran->srTRTRec.TransactionCode==SALE) &&
		(fGetImamPrivateLabel())){
		memset((char *)srISO.pszField63, 0x00, sizeof(srISO.pszField63));
		if (strlen(pobTran->srBRec.szCustNum)<(PRIVATE_LABEL_SIZE+2)) 
			strncpy((char *)srISO.pszField63, "EC0000000000", (PRIVATE_LABEL_SIZE+2) - strlen(pobTran->srBRec.szCustNum));
		strcat((char *)srISO.pszField63, pobTran->srBRec.szCustNum);
		return;
   	}

    if ((pobTran->srBRec.inCode != CLS_BATCH) && (pobTran->srBRec.inCode != CLS_BATCH_UPLOAD))
        return;
    if (inGetHostTotals (pobTran, (ACCUM_REC *)&srHostTotals) != VS_SUCCESS)
            return;
/*
    dbRefundAmount = srHostTotals.srTotals[DEBIT_CARD].dbAmount[CREDIT_TRAN] + srHostTotals.srTotals[CREDIT_CARD].dbAmount[CREDIT_TRAN];
    dbSaleAmount = srHostTotals.srTotals[DEBIT_CARD].dbAmount[DEBIT_TRAN] + srHostTotals.srTotals[CREDIT_CARD].dbAmount[DEBIT_TRAN];
    lnRefundCount = srHostTotals.srTotals[DEBIT_CARD].lnCount[CREDIT_TRAN] + srHostTotals.srTotals[CREDIT_CARD].lnCount[CREDIT_TRAN];
    lnSaleCount = srHostTotals.srTotals[DEBIT_CARD].lnCount[DEBIT_TRAN] + srHostTotals.srTotals[CREDIT_CARD].lnCount[DEBIT_TRAN];
*/
	{
    dbDebitRefundAmount = srHostTotals.srTotals[DEBIT_CARD].dbAmount[CREDIT_TRAN];
	dbRefundAmount = srHostTotals.srTotals[CREDIT_CARD].dbAmount[CREDIT_TRAN];
    dbDebitSaleAmount = srHostTotals.srTotals[DEBIT_CARD].dbAmount[DEBIT_TRAN];
	dbSaleAmount = srHostTotals.srTotals[CREDIT_CARD].dbAmount[DEBIT_TRAN];
    lnDebitRefundCount = srHostTotals.srTotals[DEBIT_CARD].lnCount[CREDIT_TRAN];
	lnRefundCount = srHostTotals.srTotals[CREDIT_CARD].lnCount[CREDIT_TRAN];
    lnDebitSaleCount = srHostTotals.srTotals[DEBIT_CARD].lnCount[DEBIT_TRAN];
	lnSaleCount = srHostTotals.srTotals[CREDIT_CARD].lnCount[DEBIT_TRAN];
	}
	{ // Amount - Currency Adjust
		if (inGetCurrencyIdx()) {

		} else {
			dbRefundAmount = dbRefundAmount*100;  
			dbSaleAmount = dbSaleAmount * 100;  
			dbDebitRefundAmount = dbDebitRefundAmount*100;  
			dbDebitSaleAmount = dbDebitSaleAmount * 100;  
		}
	}
#ifndef CITI_IND
 /*    sprintf((char *) srISO.pszField63,"%03d%012.0f%03d%012.0f%060ld",
        (int)lnSaleCount,  CITIaleAmount,
        (int)lnRefundCount, dbRefundAmount, 0L);
*/
    sprintf((char *) srISO.pszField63, "%03d", (int) lnSaleCount);
    vdDb2Str(dbSaleAmount, szScratch);
    vdTrimLeadSpaces(szScratch);
    pad(szScratch, szScratch, '0', 12, RIGHT);
	strcat((char *) srISO.pszField63, szScratch);

	sprintf(szScratch, "%03d", (int) lnRefundCount);
    strcat((char *) srISO.pszField63, szScratch);    
	vdDb2Str(dbRefundAmount, szScratch);
    vdTrimLeadSpaces(szScratch);
    pad(szScratch, szScratch, '0', 12, RIGHT);
    strcat((char *) srISO.pszField63, szScratch);

	sprintf(szScratch, "%03d", (int) lnDebitSaleCount);
    strcat((char *) srISO.pszField63, szScratch);
	vdDb2Str(dbDebitSaleAmount, szScratch);
    vdTrimLeadSpaces(szScratch);
    pad(szScratch, szScratch, '0', 12, RIGHT);
    strcat((char *) srISO.pszField63, szScratch);

	sprintf(szScratch, "%03d", (int) lnDebitRefundCount);
    strcat((char *) srISO.pszField63, szScratch);
	vdDb2Str(dbDebitRefundAmount, szScratch);
    vdTrimLeadSpaces(szScratch);
    pad(szScratch, szScratch, '0', 12, RIGHT);
    strcat((char *) srISO.pszField63, szScratch);

    //strcat((char *) srISO.pszField63, "000000");
	//strcat((char*)srISO.pszField63, "000000000000000000000000000000000000000000000000000000"); // : Make it 0090
	pad((char *) srISO.pszField63,(char *) srISO.pszField63,'0', 90, LEFT); //
#endif /* not CITI_IND*/

#ifdef CITI_IND   //We need to restrict the lenght of field 63 to 30 not 90!!!!Citibank India asked
	sprintf((char *) srISO.pszField63,"%03d", (int)lnSaleCount);
    vdDb2Str(dbSaleAmount, szScratch);
	vdTrimLeadSpaces (szScratch);
	pad(szScratch,szScratch,'0', 12, RIGHT);
	strcat((char *) srISO.pszField63, szScratch);
	sprintf(szScratch,"%03d", (int)lnRefundCount);
	strcat((char *) srISO.pszField63, szScratch);
	vdDb2Str(dbRefundAmount, szScratch);
	vdTrimLeadSpaces (szScratch);
	pad(szScratch,szScratch,'0', 12, RIGHT);
	strcat((char *) srISO.pszField63, szScratch);
	
	/*  sprintf((char *) srISO.pszField63,"%03d%012.0f%03d%012.0f",
        (int)lnSaleCount,  CITIaleAmount,
        (int)lnRefundCount, dbRefundAmount); */
#endif /*CITI_IND*/
}

/*********************************************************************************************
* @func int | inCITISettleAHost|
*
*               Calls the protocol functions to settle a specific host
*
* @parm TRANSACTION_OBJECT * |pobTran |
*       Transaction object.
*
* @rdesc Returns the success or failure.
* @flag int | VS_SUCCESS
* @flag int | VS_ERR
* @end
**********************************************************************************************/

int inCITISettleAHost(TRANSACTION_OBJECT* pobTran) {
    int inResult = VS_ERR;
    int inSaveHostHandle;
    //short fBatchUpload; //spqalog011
    char szDate[DATE_SIZE + 1],
    szTime[TIME_SIZE + 1];

    VS_BOOL fSettleSucceeded,
    fCommErr = VS_FALSE;

#ifdef  COUNTER_DEFINED
    COUNTER_OBJECT obCounter;
#endif  /* COUNTER_DEFINED */

    /**/pdebug(("--inSettleAHost--"));/**/

    /* Dont execute the following during PFR if power fails after this segment */
    if (vPFRSetPartFunc(__LINE__)) {
        memset(pobTran->szRespMsg, 0x00, RESP_MSG_SIZE);

        vdGetDate(szDate, MMDDYY);
        vdGetTime(szTime);
        strlcpy(pobTran->szSettTime, szTime, DATE_SIZE);
        strlcpy(pobTran->szSettDate, szDate, DATE_SIZE);

        inSaveHostHandle = inGetHostHandle();
        /*
             *      Open Batch for Settlement here, where we are sure proper host has already
             *      been loaded.
             */
        vdBatchDCOpen(pobTran);
        if ((fGetDemoMode() == VS_TRUE) && (fGetTrainSettle() == VS_TRUE)) {
            // CPAC2.1B
            inResult = inFakeSettle(pobTran);
            inResetDemoBatch(pobTran);
        } else {
#ifdef COUNTER_DEFINED
            inSetTimerOnOff(START_TIMER_3);
#endif  /* COUNTER_DEFINED */

            inResult = inRunSettleProtocolFunction(pobTran);

#ifdef COUNTER_DEFINED
            obCounter.inType = BATCH_SET_RESP_TIME;
            obCounter.inIndex = inGetHDTCounterIndex();
            inIncCounter(&obCounter, (int) (inSetTimerOnOff(STOP_TIMER_3)));
#endif  /* COUNTER_DEFINED */
        }


        if (inResult == VS_SUCCESS) {
            //            BT_TRACE ('I', "Settle Successful");
            vdDisplayMessageFromFile(SETTLE_SUCCESS_MSG, STATUS_MSG);
            fSettleSucceeded = VS_TRUE;
            vdSGErrorMessage(0L);
            /* vdSGErrorMessage(EMPTY_STR_ERR_MSG);*/
        } else {
            pdebug(("inPackUnpack=%d", inResult));
            /*
                     *      Settle Error Handling
                     *          Do not overwrite error set in host code
                     *          Always display SETTLE FAILED ERROR MESSAGE
                     */
            if (strlen(pobTran->szRespMsg) > 0) {
                //       BT_TRACE ('I', pobTran->szRespMsg);
            } else {
                //                BT_TRACE ('I', "Settle Failed");
            }

            if (lnGGErrorMessage() == TXMT_FAIL_ERR_MSG)
                fCommErr = VS_TRUE;

            if (!fGGAutoSettle()) /* removed single settle check */
		{

                	vdDisplayMessageFromFile(SETTLE_FAIL_ERR_MSG, WARNING_MSG);
                	ACTIVITY_LOG("Settle error - Run protocol");//citiphil_27feb_DSC_don
                	#ifdef ICICI
				/* Print Settle Failed Receipt */
				inPrintFailedSettlementMessage(pobTran, &obPrinter);
				/* Print Settle Failed Receipt */
			#endif  /*   ICICI  */
                SVC_WAIT(1000);
            }

            if (strlen(pobTran->szRespMsg) > 0)
                pad(pobTran->szRespMsg, pobTran->szRespMsg, ' ', MESSAGE_SIZE, CENTER);
            fSettleSucceeded = VS_FALSE;
        }

        /* In case the HDT record was changd during host settlement reset the HDT Table */

        if (inLoadHostData(inSaveHostHandle) != VS_SUCCESS)
            return(VS_ERR);

        inMakeTerminalTotals(pobTran, VS_FALSE, fSettleSucceeded);
        /** /pdebug(("fSettleSucceeded = %d", fSettleSucceeded));*/
    }// if (vPFRSetPartFunc(__LINE__)
    else {
        /* Because we have just recovered, the batch is set as OPEN in trans object */
        pobTran->fBatchOpen = VS_FALSE;
        vdBatchDCOpen(pobTran);
        fSettleSucceeded = VS_TRUE;
        /* Need to retrieve local variable to indicate settlement succeeded */
        inGetExternalPfrData(PFR_SETTLE_SUCCEED, (unsigned char *) &fSettleSucceeded, sizeof(VS_BOOL));
    }


    /* Need to store local variable to indicate settlement succeeded */
    inAddExternalPfrData(PFR_SETTLE_SUCCEED, (unsigned char *) &fSettleSucceeded, sizeof(VS_BOOL));

    /* If we fail at this point, then the above segment will be skipped */
    inPFRStateStoreAll(PFR_BEGIN_SETTLE_REPORT, pobTran, 1, 1);


    // inPrintSettlementReport(pobTran, VS_FALSE, fSettleSucceeded, fCommErr);

    if (fSettleSucceeded) {
        SETT_REC srLocSRec;
        SETT_KEY srLocSKey;

        //spqalog011
	// Used to fix Batch Number increment during Settlement with Batch Upload jzg 05-Mar-05
	//inGetTranFlexiData(pobTran, CITI_BATCH_UPLOAD_FLAG, (unsigned char *) &fBatchUpload, 2);

	/*if (!fBatchUpload)
	{
	    	//To fix the batch number increment issue...moved this from inReconcileCPAC
	    	if (inResetBatch(pobTran) != VS_SUCCESS)
                   return(VS_ERR);
  	}*/

		//jrd 05162005
		 //inCITISaveSummaryReport(pobTran);

        inPrintSettlementReport(pobTran, VS_FALSE, fSettleSucceeded, fCommErr);
        /* pj1 Add host name to sett_rec and set GDS*/
        inMakeTerminalTotals(pobTran, VS_FALSE, fSettleSucceeded); //CPAC2.2B
        strcpy(srRcpt.szHostName, szGetHostName());
        strcpy(srLocSRec.szHostName, srRcpt.szHostName);
        inPutSettRec(pobTran, &srLocSRec, &srLocSKey);
        //  inBackupAccum();
        /* if auto settlement do not show messages */
        if (fGGAutoSettle())
            inPurgeHostFromBatch(pobTran, inGetBatchIndex(), VS_FALSE);
        else
            inPurgeHostFromBatch(pobTran, inGetBatchIndex(), VS_TRUE);
        /* Delete open tab batch, formally done in inCheckOpenTabs() */
        //if ( inDeleteOpenTabBatch(pobTran) != VS_SUCCESS )   Saritha_b1 Opten tab batch is being deleted bug fixing.
        //vdDisplayMessageFromFile( SUSPEND_ERROR_MSG, ERROR_MSG);  Saritha_b1 Opten tab batch is being deleted bug fixing.

        /* Reset Offline count after settlement */
        if ((inResult = inResetOfflineCount()) != VS_SUCCESS)
            vdDisplayMessageFromFile(BDT_ERR_MSG, ERROR_MSG);

        if ((inResult = inResetAccum()) != VS_SUCCESS)
            vdDisplayMessageFromFile(ACCUM_ERR_MSG, ERROR_MSG);

#ifdef CLERK_DEFINED
        if ((inResult = inResetUTT(pobTran)) != VS_SUCCESS)
            vdDisplayMessageFromFile(UTT_FAIL_ERR_MSG21, ERROR_MSG);

        /* reset active clerk file bb1 */
        if ((inResult = inResetADT()) != VS_SUCCESS)
            vdDisplayMessageFromFile(ADT_FILE_ERR_MSG21, ERROR_MSG);

        inResetUDTLogedIn();
#endif /* if CLERK_DEFINED */

        /* Zero the STT File */
#ifdef SHIFT_DEFINED
        if (inResetSTT(pobTran) != VS_SUCCESS)
            vdDisplayMessageFromFile(STT_FAIL_ERR_MSG21, ERROR_MSG);
#endif
    }

    /*
     *      Must close the batch so that if this function is called again for a different host the correct
     *      batch will be opened above.
     */
    vdCloseDCBatch(pobTran);
    vdFree((char *) pobTran->srBRec.pchHostData);
    pobTran->srBRec.pchHostData = NULL;

    return(inResult);
} /* End of inSettleAHost () */

int inCITISaveSummaryReport (TRANSACTION_OBJECT *pobTran)
{
	char szDate[DATE_SIZE + 1];
	int     inStart, inStop, inNumberOfMerchants, inMerch = 0;
	int inHostIndex;
	int inReportTop = VS_TRUE;

	if ( inGetHostTranCnt(pobTran) < 1 )
	{
		vdDisplayMessageFromFile( BATCH_EMPTY_MSG, WARNING_MSG);
		//  return(BATCH_EMPTY_MSG);
		 vdSGErrorMessage(0L);
		return (VS_SUCCESS);
	}

	inNumberOfMerchants = inSelectOneAllMID(pobTran,fGetMultiMerchPrompt());//1.4
	inHostIndex=inGetHostHandle(); //LENIN
	vdSetMerchantNum(inGlobalMerchantHandle);
	if (inNumberOfMerchants == inGetMITTotRecs())
	{
		inStart = 1;
		inStop = inGetMITTotRecs();
	}
	else if (inNumberOfMerchants == 1)
	{
		inStart = inGetMerchantNum();
		inStop = inGetMerchantNum();
	}
	else
	{
		inStart = 1;
		inStop = 0;
	}

	inMerch=inGetMerchantNum();;

	if (inLoadMITRec(inMerch-1) != VS_SUCCESS)
	{
		return(VS_ERR);
	}

        /* Get the total number of records in the batch */
        if (inGetDCBatchRecCnt(pobTran) == 0)
        {
            	vdDisplayMessageFromFile( BATCH_EMPTY_MSG, WARNING_MSG);
            	vdCloseDCBatch(pobTran); /* bb1 */
            	/* loop back for next merchant */
            	return (VS_ERR);
        }

        vdCloseDCBatch(pobTran); /* bb1 */

        if (inGGCode() == SETTLE)
        {
		vdGetDate(szDate,MMDDYY);
		strlcpy (pobTran->szSettDate, szDate, DATE_SIZE);
		//leo_nosourcesafe
		#ifdef CITI_IND
			vdGetDate(srRcpt.szDate, YYMMDD);
			vdFormatCITIDate(srRcpt.szDate);
		#endif /*CITI_IND*/
	 }

	if (inLoadDefaultHost (inHostIndex) != VS_SUCCESS) //1.4
		return (VS_ERR);

	if (inLoadDefaultCurrency (pobTran) != VS_SUCCESS)
		return (VS_ERR);

	if ( fIsIndependentBatch ( inGetHostHandle() ))  // 1.4
	{
		if (inCITISaveSummaryMiddle (pobTran, &inReportTop, inNumberOfMerchants) != VS_SUCCESS)
			return (VS_ERR);
	}

    	return(VS_SUCCESS);
}


int inCITISaveSummaryMiddle (TRANSACTION_OBJECT *pobTran, int *pinReportTop, int inNumberOfMerchants)
{
//    int inHostIdx; CPAC_LINT_REMOVED
    int  inNewHost;
   CARD_TOTS_REC srGrandTots;

#ifdef CITI_IND
   RCPT_FIELDS srTempRcpt;
#endif /* CITI_IND CPAC_LINT */

/*   Saritha_b1...........Start............Reprint Settlement Report  */

// #ifdef TLFB   (Made this feature as the part of CPAC Base Application)
	char szSFileName[FILENAME_SIZE + 1];
	int inRecCnt = 1;
// #endif /*  TLFB  */  (Made this feature as the part of CPAC Base Application)

/*   Saritha_b1............End.............Reprint Settlement Report  */

    int inIssuer=0;
    int inIssuerCnt=0;
    int inGrandIssuerCnt = 0;
    int inRetVal=0;
    long lnRecNum=0L;
    int inNegPos;
    char szCurSym[CUR_SYMBOL_SIZE + 1];
    long lnCount=0L, lnAmount=0L, lnTip=0L, lnTotal=0L, lnTax=0L, lnSurCharge=0L, lnCashBack=0L;
    long lnDebitCount=0L, lnCreditCount=0L , lnAdjustCount=0L , lnNetCount=0L;
    long lnDebitAmount=0L, lnCreditAmount=0L, lnAdjustAmount=0L , lnNetAmount=0L;
    long lnSaleCount=0L, lnRefundCount=0L, lnVoidSaleCount=0L, lnVoidRefundCount=0L, lnTotalCount=0L;
    double  dbSaleAmount=0.0 , dbRefundAmount=0.0, dbVoidSaleAmount=0.0, dbVoidRefundAmount=0.0 , dbTotalAmount=0.0;
	    unsigned char ucIITTempRec[SIZE_IIT_REC+1];


    double dbGrandSaleAmount=0.0, dbGrandRefundAmount=0.0, dbGrandVoidSaleAmount=0.0, dbGrandVoidRefundAmount=0.0, dbGrandTotalAmount=0.0;
    long lnGrandSaleCount=0L, lnGrandRefundCount=0L, lnGrandVoidSaleCount=0L, lnGrandVoidRefundCount=0L, lnGrandTotalCount=0L;

    long lnOfflineCount=0L, lnGrandOfflineCount=0L;
      long lnEPPSaleCount=0L, lnGrandEPPSaleCount=0L;

    double dbOfflineAmount=0.0,dbGrandOfflineAmount=0.0;
    double dbEPPSaleAmount=0.0,dbGrandEPPSaleAmount=0.0;

    char szFileName [FILENAME_SIZE + 1];
    DB_FILE srDBFPtr;
    ACCUM_REC srAccumRec;
    ACCUM_KEY srAccumKey;
    ACCUM_SKEY srAccumSKey;
    int inKeyIdx=0;
    int inResult=0;

    long lnAdjustNum=0;

    FHANDLE hFHandle;
    ACCUM_SHIFT srASI;
/* LENIN CPAC #if TBD_CPAC */
//	IIT_REC srCPACIITRec; cpac_2.2a
/* LENIN CPAC #endif  TBD_CPAC */

   //memset(&srRcpt, 0, sizeof(RCPT_FIELDS)); //leo_nov1400
   memset((char *)&srGrandTots, 0x00, (SIZE_CARD_TOTS_REC));
/*  {
        srGrandTots.inTotalCnt = 0;
        srGrandTots.lnTotalAmt = 0L;
        srGrandTots.lnSaleAmt  = 0L;
        srGrandTots.lnTipAmt   = 0L;
        srGrandTots.lnTaxAmt   = 0L;
        srGrandTots.lnSurCharge   = 0L;
        srGrandTots.lnCashBack   = 0L;
	   }
*/
    vdGetAccumFName (szFileName);
    #ifdef CITI_PHIL
    if (inGGCode() == SETTLE) {
		if (lnCPACMiddleCondition&0x02000000)
			lnAdjustNum=1L;
	}
	#endif /* CITI_PHIL */
//leo_nosourcesafe
#ifdef CITI_IND
    if (inGGCode() == SETTLE) {
		if (lnCPACMiddleCondition&0x02000000)
			lnAdjustNum=1L;
	}
#endif /* CITI_IND */
    if (inOpenAccum(&srDBFPtr, szFileName) != VS_SUCCESS)
    {

        vdSGErrorMessage(BATCH_ERR_MSG);
        return(VS_ERR);
    }

    vdCPACSetSummaryMiddleCondition ();

    /*  Read ASI File to use for determining if issuer accumulator has been updated */


    vdGetASIFName(szFileName);
    if ((hFHandle = open(szFileName, O_RDWR)) < 0)
    {
        if ((hFHandle = open(szFileName, O_CREAT|O_RDWR)) < 0)
            return(VS_ERR);

        memset((char *) &srASI,0x00,SIZE_ACCUM_SHIFT);

    }
    else
        inResult = read(hFHandle, (char *) &srASI, SIZE_ACCUM_SHIFT);

    close(hFHandle);

	srAccumSKey.compare_func = inAccumCompFn;
    inNewHost = VS_TRUE;
    inIssuerCnt = 0;

    for (inIssuer = 0; inIssuer < TOTAL_ISSUERS; inIssuer++)
    {


    #if 0
        if (srASI.srIssuer.fActiveAccum[inIssuer] == '\0')
            continue;

		inGetIssuerRecord(inIssuer);
#ifdef CITI_IND
		memcpy(&srTempRcpt.unFrm.srSubTotal.srTerm, &srRcpt.unFrm.srSubTotal.srTerm, sizeof(srRcpt.unFrm.srSubTotal.srTerm)); //leo_nov1300

#endif
		strlcpy(srRcpt.unFrm.srSummary.srMid.szCType, srCPACIITRec.szIssuerLabel, CLABEL_SIZE);
#endif /* 0 */

   if ((inLoadIITRecFromStruct( inIssuer, ucIITTempRec)) == VS_ERR)
        {
		    inCloseAccum(&srDBFPtr);
	        vdSGErrorMessage(IIT_ERR_MSG21);
			return(VS_ERR);
        }

        if (srASI.srIssuer.fActiveAccum[inGetIssuerNumberFromStruct(ucIITTempRec)] == '\0')
            continue;
#ifdef CITI_IND
		memcpy(&srTempRcpt.unFrm.srSubTotal.srTerm, &srRcpt.unFrm.srSubTotal.srTerm, sizeof(srRcpt.unFrm.srSubTotal.srTerm)); //leo_nov1300

#endif
        strlcpy(srRcpt.unFrm.srSummary.srMid.szCType, szGetIssuerLabelFromStruct(ucIITTempRec),CLABEL_SIZE);


    //    srAccumKey.inIssuerNumber = inIssuer;
    //    srAccumSKey.accumKey.inIssuerNumber = inIssuer;
         srAccumKey.inIssuerNumber = inGetIssuerNumberFromStruct( ucIITTempRec );
        srAccumSKey.accumKey.inIssuerNumber = inGetIssuerNumberFromStruct(ucIITTempRec);
		/* If record does not exist then go to next issuer */
        inRetVal = inKeyReadAccum (&srDBFPtr, &srAccumRec, &srAccumKey, &srAccumSKey, &lnRecNum);
        if (inRetVal == VS_SUCCESS)
        {

			long2str (srRcpt.szBatchNum, (lnGetBatchNum()-lnAdjustNum));
            if (inNewHost)
            {
                if (*pinReportTop == VS_TRUE)
                {
                    vdMakeReportHeader(pobTran);
                    if (inGetMITTotRecs() == 1 || inNumberOfMerchants == 1) {

                    	long2str (srRcpt.szBatchNum, (lnGetBatchNum()-lnAdjustNum));
                    	//sprintf(srRcpt.szBatchNum, "%03ld", lnGetBatchNum());
                    //	strcpy (srRcpt.szBatchNum,pobTran->szBatchNum);/* Lenin */

            //          inPrintReceiptHeader(pobTran);
					}
                    else
                    {	long2str (srRcpt.szBatchNum, (lnGetBatchNum()-lnAdjustNum));
                    	//sprintf(srRcpt.szBatchNum, "%03ld", lnGetBatchNum());
                       // if (inPrintLines(pobPrinter, REPORT_HEADER_START, REPORT_HEADER_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS)
                       //     return(VS_ERR);
					//Kelvin_F2 --- start: fix the bug for if single merchant, double header...
					//Kelvin_F2 Bug fix for handle decrease 29apr2002
						//inPrintReceiptHeader(pobTran);
		//				if (inPrintReceiptHeader(pobTran)!= VS_SUCCESS)
			//			{
				//			inCloseAccum(&srDBFPtr);
					//		return(VS_ERR);
						//}
					//Kelvin_F2 --- end: fix the bug for if single merchant, double header...
                    }
                }

                inNewHost = VS_FALSE;
                /* Header condition should not print report title except at top of report */
                vdCPACSetSummaryHeaderCondition (*pinReportTop,pobTran, VS_FALSE);
                    *pinReportTop = VS_FALSE;

                strlcpy(srRcpt.szMerchantName,szGetMerchantText(), sizeof(srRcpt.szMerchantName));
                strlcpy(srRcpt.szHostName,szGetHostName(), sizeof(srRcpt.szHostName));
#ifdef CITI_PHIL
				//Kelvin_F2 --- start: no need to mask TID
#ifdef MASK_TID_AND_MID
                vdMaskCitiMTID();
#endif
				//Kelvin_F2 --- end: no need to mask TID
#endif /* CITI_PHIL */
		//leo_nosourcesafe
#ifdef CITI_IND
				vdGetDate(srRcpt.szDate, YYMMDD);
				vdFormatCITIDate(srRcpt.szDate);
#endif /*CITI_IND*/
                pad (srRcpt.szBatchNum, srRcpt.szBatchNum, '0', inGetBatchNumSize(), RIGHT); // Lenin 1.4
           //     if (inPrintLines(pobPrinter, CPAC_SUMMARY_TOP_START,CPAC_SUMMARY_TOP_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS)
               // {           //Kelvin_F2 Bug fix for handle decrease 29apr2002
					        //    return(VS_ERR);
			//				inCloseAccum(&srDBFPtr);
				//			return(VS_ERR);
				//}


/*Saritha_b1.............Start...........Amex SOC Printing */
#ifdef AMEX_SOC
	if(inGGOpCode() == SETTLE_OPERATION)
	{
	     	strcpy( srRcpt.unFrm.srReceipt.szGenBuf2, (char*)srISO.pszField62);
    	        //Praveen_30/01/2003_Changed to Host File Name
       	 if(strcmp(szGetHostFileName(), "AXAP")==0)
        	{
           	//	if (inPrintLines(&obPrinter, AMEX_SOC_PRINT_START,AMEX_SOC_PRINT_END, NO_BL_LINE, 4L) != VS_SUCCESS)
                //{           //Kelvin_F2 Bug fix for handle decrease 29apr2002
					        //    return(VS_ERR);
			//				inCloseAccum(&srDBFPtr);
				//			return(VS_ERR);
				//}
        	}
        	else
        	{
           		// If it is not AXAP, depend on condition line set in TPL file.
           	//	if (inPrintLines(&obPrinter, AMEX_SOC_PRINT_START,AMEX_SOC_PRINT_END, NO_BL_LINE, 2L) != VS_SUCCESS)
               // {           //Kelvin_F2 Bug fix for handle decrease 29apr2002
					        //    return(VS_ERR);
			//				inCloseAccum(&srDBFPtr);
				//			return(VS_ERR);
				//}
        	}
	}

#endif  /*   AMEX_SOC */

/* Saritha_b1.............End...........Amex SOC Printing */

/*Saritha_b1.............Start...........Reprint Settlement Report */

// #ifdef TLFB  (Made this feature as the part of CPAC Base Application)

			if (inGGCode() == SETTLE)
			{
				vdGetReprintSettleFileName(szSFileName, CPAC_HEADER);

				if (inDBFileExists(szSFileName) == VS_SUCCESS)
						inDBRemoveFile(szSFileName);

				if (inDBFileExists(szSFileName) != VS_SUCCESS)
					if (inDBCreateFile(szSFileName, sizeof (srCPACSettleHeader)) != VS_SUCCESS)
							ACTIVITY_LOG("HDR Fopen failed");//return(VS_ERROR);

				memset (&srCPACSettleHeader, 0x00, sizeof(srCPACSettleHeader));

				strcpy(srCPACSettleHeader.szDate, srRcpt.szDate);
				strcpy(srCPACSettleHeader.szTime, srRcpt.szTime);
				strcpy(srCPACSettleHeader.szMID, srRcpt.szMerchantId);
				strcpy(srCPACSettleHeader.szTID, srRcpt.szTermId);
				strcpy(srCPACSettleHeader.szBatchNum, srRcpt.szBatchNum);
				strcpy(srCPACSettleHeader.szHostName, srRcpt.szHostName);
				srCPACSettleHeader.lnHeaderCond = lnHeaderCondition;

				#ifdef AMEX_SOC
					strcpy(srCPACSettleHeader.szSOC, srRcpt.unFrm.srReceipt.szGenBuf2);
				#endif /*  AMEX_SOC */

				if (inDBWriteRecord(szSFileName, 1, (unsigned char *)&srCPACSettleHeader) < 0)
					ACTIVITY_LOG("Hdr storage failed");

            		}
			// #endif   /* TLFB */   (Made this feature as the part of CPAC Base Application)
                    /*Saritha_b1..............End............Reprint Settlement Report */

            }
            /*  Use totals from record */


            lnSaleCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] +
             			  srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] ;

             lnRefundCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN] +
               			     srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];

			lnVoidSaleCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[VOID_SALE_TRAN] +
             			  srAccumRec.srTotals[DEBIT_CARD].lnCount[VOID_SALE_TRAN];

			lnVoidRefundCount=srAccumRec.srTotals[CREDIT_CARD].lnCount[VOID_REFUND_TRAN] +
             			  srAccumRec.srTotals[DEBIT_CARD].lnCount[VOID_REFUND_TRAN];


			lnTotalCount = lnSaleCount+lnRefundCount+lnVoidSaleCount+lnVoidRefundCount;

 		lnOfflineCount = srAccumRec.srTotals[CREDIT_CARD].dbCustom1[SALE_TRAN] +
             			  srAccumRec.srTotals[DEBIT_CARD].dbCustom1[SALE_TRAN] ;

 		lnEPPSaleCount= srAccumRec.srTotals[CREDIT_CARD].dbCustom3[SALE_TRAN] +
             			  srAccumRec.srTotals[DEBIT_CARD].dbCustom3[SALE_TRAN] ;




          /* lnCreditCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] +
                      srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] ;
	   lnDebitCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN]                          + srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];


            lnCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] +
                      srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] +
                      srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN] +
                      srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];

*/


			dbSaleAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[SALE_TRAN]
						+ srAccumRec.srTotals[DEBIT_CARD].dbAmount[SALE_TRAN];
			dbRefundAmount=srAccumRec.srTotals[CREDIT_CARD].dbAmount[REFUND_TRAN]
						+ srAccumRec.srTotals[DEBIT_CARD].dbAmount[REFUND_TRAN];

            dbVoidSaleAmount= srAccumRec.srTotals[CREDIT_CARD].dbAmount[VOID_SALE_TRAN]
           				   + srAccumRec.srTotals[DEBIT_CARD].dbAmount[VOID_SALE_TRAN];

	    dbVoidRefundAmount=srAccumRec.srTotals[CREDIT_CARD].dbAmount[VOID_REFUND_TRAN]
	    					+ srAccumRec.srTotals[DEBIT_CARD].dbAmount[VOID_REFUND_TRAN];
		dbTotalAmount= dbSaleAmount-dbRefundAmount;
		//-lnVoidSaleAmount;

		dbOfflineAmount = srAccumRec.srTotals[CREDIT_CARD].dbCustom2[SALE_TRAN]
						+ srAccumRec.srTotals[DEBIT_CARD].dbCustom2[SALE_TRAN];

		dbEPPSaleAmount=srAccumRec.srTotals[CREDIT_CARD].dbCustom4[SALE_TRAN]
						+ srAccumRec.srTotals[DEBIT_CARD].dbCustom4[SALE_TRAN];///ivan

#ifdef CITI_PHIL
          if (lnSaleCount >= lnOfflineCount){
				lnSaleCount-=lnOfflineCount;
				dbSaleAmount-=dbOfflineAmount;
			}
	   //jrd 05122005
          /*if (lnSaleCount >= lnEPPSaleCount){
				lnSaleCount-=lnEPPSaleCount;
				dbSaleAmount-=dbEPPSaleAmount;
			}*/

#ifdef  SHELL_FLEET
	lnSaleCount+=lnOfflineCount;
	dbSaleAmount+=dbOfflineAmount;
	lnSaleCount+=lnEPPSaleCount;
	dbSaleAmount+=dbEPPSaleAmount;

#endif /* SHELL_FLEET */
#endif /* CITI_PHIL */

            /* Set print line */

	     sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_LD, lnSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szDebitCount, SUBSTITUTE_LD, lnRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustCount, SUBSTITUTE_LD, lnVoidSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szReversalCount, SUBSTITUTE_LD, lnVoidRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnTotalCount);
	     sprintf(srRcpt.unFrm.srSummary.srMid.szShiftNumber, SUBSTITUTE_LD, lnOfflineCount);
	     sprintf(srRcpt.unFrm.srSummary.srMid.szEPPSaleCount, SUBSTITUTE_LD, lnEPPSaleCount);


            /* Total Amount */
       vdDb2Str(dbSaleAmount,srRcpt.unFrm.srSummary.srMid.szCreditTotal);
	vdDb2Str(dbRefundAmount,srRcpt.unFrm.srSummary.srMid.szDebitTotal);
  	vdDb2Str(dbVoidSaleAmount ,srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
   	vdDb2Str(dbVoidRefundAmount,srRcpt.unFrm.srSummary.srMid.szReversalTotal);
    	vdDb2Str(dbTotalAmount,srRcpt.unFrm.srSummary.srMid.szNetTotal);
     	vdDb2Str(dbOfflineAmount,srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
     	vdDb2Str(dbEPPSaleAmount,srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal);

            //sprintf(srRcpt.unFrm.srSummary.srMid.szCreditTotal, SUBSTITUTE_LD, lnSaleAmount);
          //  sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD, lnRefundAmount);
          //  sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD, lnVoidSaleAmount);
         //   sprintf(srRcpt.unFrm.srSummary.srMid.szReversalTotal, SUBSTITUTE_LD, lnVoidRefundAmount);
         //   sprintf(srRcpt.unFrm.srSummary.srMid.szNetTotal, SUBSTITUTE_LD, lnTotalAmount);
	// 	sprintf(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, SUBSTITUTE_LD, lnOfflineAmount);
            /* will put dollar sign in front */
            /* vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal);  */
            //vdPutDecPoint(srRcpt.unFrm.srSummary.srMid.szCreditTotal);
            /* Sale Amount (Base Amount)*/
           /* LENIN  sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD,
                (lnAmount - lnTip - lnTax - lnSurCharge - lnCashBack)); */
            //vdPutDecPoint(srRcpt.unFrm.srSummary.srMid.szDebitTotal);
            /*Tip Amount */
            //sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD, lnTip);
            //vdPutDecPoint(srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
            /*CashBack Amount */
            //sprintf(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, SUBSTITUTE_LD, lnCashBack);
            //vdPutDecPoint(srRcpt.unFrm.srSummary.srMid.szCashBackTotal);
            // if (inPrintLines(pobPrinter, SUMMARY_TOP_START, SUMMARY_TOP_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS)
             //       return(VS_ERR);

             vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal, VS_TRUE);
             vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal, VS_TRUE);
             vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, VS_TRUE);
             vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szReversalTotal, VS_TRUE);
             vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szNetTotal, VS_TRUE);
             vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, VS_TRUE);
		vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal, VS_TRUE);

/*  KK removed these lines to avoid two '-' sumbols from the total.

 			if ((lnSaleAmount - lnRefundAmount)< -999999999L) {

          		vdGetCSTCurSymbol(szCurSym);
          		inNegPos=strlen(szCurSym);
          		srRcpt.unFrm.srSummary.srMid.szNetTotal[inNegPos]='-';

         	 }

*/
            // inGetIssuerRecord(inIssuer, &srCPACIITRec);
			//strlcpy(srRcpt.unFrm.srSummary.srMid.szCType, srIDTRec.szIssuerLabel, CLABEL_SIZE);
			//vdGetIssuerLabel(srRcpt.unFrm.srSummary.srMid.szCType);


    //        if (inPrintLines(pobPrinter, CPAC_SUMMARY_MIDDLE_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
        //    {           //Kelvin_F2 Bug fix for handle decrease 29apr2002
					        //    return(VS_ERR);
		//					inCloseAccum(&srDBFPtr);
			//				return(VS_ERR);
			//}


		/*Saritha_b1.............Start...........Reprint Settlement Report */
			// #ifdef TLFB   (Made this feature as the part of CPAC Base Application)

			if(inGGCode() == SETTLE)
			{
				vdGetReprintSettleFileName(szSFileName, CPAC_BODY);

				 //if (inDBFileExists(szSFileName) == VS_SUCCESS)  By kelvin_f2 multi_issuer
					if ((inDBFileExists(szSFileName) == VS_SUCCESS) && (inRecCnt == 1))
						inDBRemoveFile(szSFileName);


				if (inDBFileExists(szSFileName) != VS_SUCCESS)
					if (inDBCreateFile(szSFileName, sizeof (srCPACSettleMiddle)) != VS_SUCCESS)
							ACTIVITY_LOG("Bdy Fopen failed");//return(VS_ERROR);

				memset (&srCPACSettleMiddle, 0x00, sizeof(srCPACSettleMiddle));

				strcpy(srCPACSettleMiddle.szCardName, srRcpt.unFrm.srSummary.srMid.szCType);
				strcpy(srCPACSettleMiddle.szCreditCnt, srRcpt.unFrm.srSummary.srMid.szCreditCount);
				strcpy(srCPACSettleMiddle.szCreditTot, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
				strcpy(srCPACSettleMiddle.szDebitCnt, srRcpt.unFrm.srSummary.srMid.szDebitCount);
				strcpy(srCPACSettleMiddle.szDebitTot, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
				strcpy(srCPACSettleMiddle.szShiftNum, srRcpt.unFrm.srSummary.srMid.szShiftNumber);
				strcpy(srCPACSettleMiddle.szSurCharge, srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
				strcpy(srCPACSettleMiddle.szAdjCnt, srRcpt.unFrm.srSummary.srMid.szAdjustCount);
				strcpy(srCPACSettleMiddle.szAdjTot, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
				strcpy(srCPACSettleMiddle.szReversalCnt, srRcpt.unFrm.srSummary.srMid.szReversalCount);
				strcpy(srCPACSettleMiddle.szReversalTot, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
				strcpy(srCPACSettleMiddle.szNetCnt, srRcpt.unFrm.srSummary.srMid.szNetCount);
				strcpy(srCPACSettleMiddle.szNetTot, srRcpt.unFrm.srSummary.srMid.szNetTotal);
				strcpy(srCPACSettleMiddle.szEPPSaleCount, srRcpt.unFrm.srSummary.srMid.szEPPSaleCount);
				strcpy(srCPACSettleMiddle.szEPPSaleSurchrgeTotal, srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal);
				srCPACSettleMiddle.lnMiddleCond = 0x00000001L; // Add as below is commented
/*  Commentted
				if(shGetHostGroupRef() == 4)  //EPP HOST being selected.
				{
            		 		srCPACSettleMiddle.lnMiddleCond =  0x00000010L;
				}
				else if(shGetHostGroupRef() == 5)
						srCPACSettleMiddle.lnMiddleCond = 0x00000020L;

					else if(shGetHostGroupRef() == 6)
						 	srCPACSettleMiddle.lnMiddleCond = 0x00000040L;
						else
							srCPACSettleMiddle.lnMiddleCond = 0x00000001L;
*/
				if (inDBWriteRecord(szSFileName, inRecCnt, (unsigned char *)&srCPACSettleMiddle) < 0)
					ACTIVITY_LOG("Settle Middle Failed");

				inRecCnt++;

			}
			// #endif   /* TLFB */  (Made this feature as the part of CPAC Base Application)
                    /*Saritha_b1..............End............Reprint Settlement Report






         //   if (act_kbd_pending_test(KEY_CANCEL)) (Saritha_b1 commented )
             //   return(VS_ESCAPE); 	(Saritha_b1 commented )*/

            /* Accumulate totals */


/*            srGrandTots.inTotalCnt += (int)(lnSaleCount+lnRefundCount+lnVoidSaleCount+lnVoidRefundCount);
            srGrandTots.lnTotalAmt += dbTotalAmount;
            srGrandTots.lnSaleAmt  += (dbSaleAmount);
            srGrandTots.lnTipAmt   += dbTip;
            srGrandTots.lnTaxAmt    += dbTax;
            srGrandTots.lnSurCharge += dbSurCharge;
            srGrandTots.lnCashBack  += dbCashBack;
*/

			lnGrandTotalCount+=(int)(lnSaleCount+lnRefundCount+lnVoidSaleCount+lnVoidRefundCount+lnOfflineCount+lnEPPSaleCount );

			lnGrandSaleCount+=lnSaleCount;
			lnGrandRefundCount+=lnRefundCount;
			lnGrandVoidSaleCount+=lnVoidSaleCount;
			lnGrandVoidRefundCount+=lnVoidRefundCount;
			lnGrandOfflineCount+=lnOfflineCount;
			lnGrandEPPSaleCount+=lnEPPSaleCount;


			dbGrandSaleAmount += dbSaleAmount;
			dbGrandRefundAmount+= dbRefundAmount;
			dbGrandVoidSaleAmount+= dbVoidSaleAmount;
			dbGrandVoidRefundAmount+=dbVoidRefundAmount;
			dbGrandOfflineAmount+=dbOfflineAmount;
			dbGrandEPPSaleAmount+=dbEPPSaleAmount;

			//( lnSaleCount+lnRefundCount+lnVoidSaleCount+lnVoidRefundCount);


            inIssuerCnt++;
            if (inIssuerCnt > inGrandIssuerCnt)
                inGrandIssuerCnt = inIssuerCnt;
#ifdef CITI_IND

		memcpy(&srRcpt.unFrm.srSubTotal.srTerm, &srTempRcpt.unFrm.srSubTotal.srTerm, sizeof(srRcpt.unFrm.srSubTotal.srTerm));

#endif
        }
    }
    inCloseAccum(&srDBFPtr);

    /* Print Grand Totals if more than one issuer */
    if (inIssuerCnt > 1)
    {
        if (inGrandIssuerCnt > 1)
        {
        #if 0 /* LENIN */
            /* Set print line */
            sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_D,
                srGrandTots/*[TOTAL_ISSUERS]*/.inTotalCnt);

            /* Total Amount */
            sprintf(srRcpt.unFrm.srSummary.srMid.szCreditTotal, SUBSTITUTE_LD,
                srGrandTots/*[TOTAL_ISSUERS]*/.lnTotalAmt);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal);
            /* Sale Amount */
            sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD,
                srGrandTots/*[TOTAL_ISSUERS]*/.lnSaleAmt);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal);
            /*Tip Amount */
            sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD,
                srGrandTots/*[TOTAL_ISSUERS]*/.lnTipAmt);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
            /*Tax Amount */
            sprintf(srRcpt.unFrm.srSummary.srMid.szTaxTotal, SUBSTITUTE_LD,
                srGrandTots/*[TOTAL_ISSUERS]*/.lnTaxAmt);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szTaxTotal);
            /*Surcharge Amount */

            sprintf(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, SUBSTITUTE_LD,
                srGrandTots/*[TOTAL_ISSUERS]*/.lnSurCharge);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
            /*CashBack Amount */
            sprintf(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, SUBSTITUTE_LD,
                srGrandTots/*[TOTAL_ISSUERS]*/.lnCashBack);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCashBackTotal);

            /* Send VS_TRUE so FORM_FEED will print */
            #endif /* 0 */
#ifdef CITI_IND
		memcpy(&srTempRcpt.unFrm.srSubTotal.srTerm, &srRcpt.unFrm.srSubTotal.srTerm, sizeof(srRcpt.unFrm.srSubTotal.srTerm)); //leo_nov1300

#endif
//            lnGrandTotalAmount=lnGrandSaleAmount-lnGrandRefundAmount+lnGrandVoidRefundAmount-lnGrandVoidSaleAmount;
            dbGrandTotalAmount=dbGrandSaleAmount-dbGrandRefundAmount+dbGrandOfflineAmount;//jrd +dbGrandEPPSaleAmount;

#ifdef CITI_IND

		dbGrandTotalAmount=dbGrandSaleAmount-dbGrandRefundAmount;

#endif /*CITI_IND*/
            //+lnGrandVoidRefundAmount-lnGrandVoidSaleAmount;
			//if (lnGrandSaleCount >= lnGrandOfflineCount){
			//	lnGrandSaleCount-=lnGrandOfflineCount;
			//	lnGrandSaleAmount-=lnGrandOfflineAmount;
			//}




 			sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_LD, lnGrandSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szDebitCount, SUBSTITUTE_LD, lnGrandRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustCount, SUBSTITUTE_LD, lnGrandVoidSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szReversalCount, SUBSTITUTE_LD, lnGrandVoidRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnGrandTotalCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szShiftNumber, SUBSTITUTE_LD, lnGrandOfflineCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szEPPSaleCount, SUBSTITUTE_LD, lnGrandEPPSaleCount);




		vdDb2Str(dbGrandSaleAmount,srRcpt.unFrm.srSummary.srMid.szCreditTotal);
		vdDb2Str(dbGrandRefundAmount,srRcpt.unFrm.srSummary.srMid.szDebitTotal);
		vdDb2Str(dbGrandVoidSaleAmount,srRcpt.unFrm.srSummary.srMid.szAdjustTotal);

		vdDb2Str(dbGrandVoidRefundAmount,srRcpt.unFrm.srSummary.srMid.szReversalTotal);
		vdDb2Str(dbGrandTotalAmount,srRcpt.unFrm.srSummary.srMid.szNetTotal);
		vdDb2Str(dbGrandOfflineAmount,srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
		vdDb2Str(dbGrandEPPSaleAmount, srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal);

			//sprintf(srRcpt.unFrm.srSummary.srMid.szCreditTotal, SUBSTITUTE_LD, lnGrandSaleAmount);
          //  sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD, lnGrandRefundAmount);
       //     sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD, lnGrandVoidSaleAmount);
           // sprintf(srRcpt.unFrm.srSummary.srMid.szReversalTotal, SUBSTITUTE_LD, lnGrandVoidRefundAmount);
         //   sprintf(srRcpt.unFrm.srSummary.srMid.szNetTotal, SUBSTITUTE_LD, lnGrandTotalAmount);
			//sprintf(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, SUBSTITUTE_LD, lnGrandOfflineAmount);


 			vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szReversalTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szNetTotal, VS_TRUE);
			vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, VS_TRUE);


        	if ((dbGrandSaleAmount - dbGrandRefundAmount)< -99999999999.00) {
          		strcpy (szCurSym,szGetCurSymbol());

          		inNegPos=strlen(szCurSym);
          		srRcpt.unFrm.srSummary.srMid.szNetTotal[inNegPos]='-';

         	 }
            vdCPACSetSummaryBottomCondition (pobTran, VS_TRUE, &srGrandTots/*[TOTAL_ISSUERS]*/);
	//		if (inPrintLines(pobPrinter, CPAC_GRANT_TOTAL_LABEL_START, CPAC_GRANT_TOTAL_LABEL_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
           //     return(VS_ERR);
			//Kelvin_F2 --- start: use CPAC_SUMMARY_BOTTOM_START and CPAC_SUMMARY_BOTTOM_END
            // if (inPrintLines(pobPrinter, SUMMARY_BOTTOM_START, SUMMARY_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
           // if (inPrintLines(pobPrinter, CPAC_SUMMARY_BOTTOM_START, CPAC_SUMMARY_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
			//Kelvin_F2 --- start: use CPAC_SUMMARY_BOTTOM_START and CPAC_SUMMARY_BOTTOM_END
               // return(VS_ERR);

		/*Saritha_b1.............Start...........Reprint Settlement Report */
		// #ifdef TLFB  (Made this feature as the part of CPAC Base Application)

			if(inGGCode() == SETTLE)
			{

				memset (&srCPACSettleMiddle, 0x00, sizeof(srCPACSettleMiddle));
				strcpy(srCPACSettleMiddle.szCardName, srRcpt.unFrm.srSummary.srMid.szCType);
				strcpy(srCPACSettleMiddle.szCreditCnt, srRcpt.unFrm.srSummary.srMid.szCreditCount);
				strcpy(srCPACSettleMiddle.szCreditTot, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
				strcpy(srCPACSettleMiddle.szDebitCnt, srRcpt.unFrm.srSummary.srMid.szDebitCount);
				strcpy(srCPACSettleMiddle.szDebitTot, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
				strcpy(srCPACSettleMiddle.szShiftNum, srRcpt.unFrm.srSummary.srMid.szShiftNumber);
				strcpy(srCPACSettleMiddle.szSurCharge, srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
				strcpy(srCPACSettleMiddle.szAdjCnt, srRcpt.unFrm.srSummary.srMid.szAdjustCount);
				strcpy(srCPACSettleMiddle.szAdjTot, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
				strcpy(srCPACSettleMiddle.szReversalCnt, srRcpt.unFrm.srSummary.srMid.szReversalCount);
				strcpy(srCPACSettleMiddle.szReversalTot, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
				strcpy(srCPACSettleMiddle.szNetCnt, srRcpt.unFrm.srSummary.srMid.szNetCount);
				strcpy(srCPACSettleMiddle.szNetTot, srRcpt.unFrm.srSummary.srMid.szNetTotal);
				strcpy(srCPACSettleMiddle.szEPPSaleCount, srRcpt.unFrm.srSummary.srMid.szEPPSaleCount);
				strcpy(srCPACSettleMiddle.szEPPSaleSurchrgeTotal, srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal);
				srCPACSettleMiddle.lnMiddleCond = lnBottomCondition;

				if (inDBFileExists(szSFileName) == VS_SUCCESS)
					if (inDBWriteRecord(szSFileName, inRecCnt, (unsigned char *)&srCPACSettleMiddle) < 0)
						ACTIVITY_LOG("Settle Middle Failed");
			}
		// #endif   /* TLFB */  (Made this feature as the part of CPAC Base Application)
             /*Saritha_b1..............End............Reprint Settlement Report */
        }
    }
#if CITI_PHIL
    if (inGGCode() == SETTLE) {


    lnMiddleCondition = lnCPACMiddleCondition;


 //    if (inPrintLines(&obPrinter, CPAC_SETTLEMENT_STATUS_START, CPAC_SETTLEMENT_STATUS_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
     //   	return(VS_ERR);

	/*Saritha_b1.............Start...........Reprint Settlement Report */
		// #ifdef TLFB  (Made this feature as the part of CPAC Base Application)
			if(inGGCode() == SETTLE)
			{

				vdGetReprintSettleFileName(szSFileName, CPAC_FOOTER);

				if (inDBFileExists(szSFileName) == VS_SUCCESS)
						inDBRemoveFile(szSFileName);

				if (inDBFileExists(szSFileName) != VS_SUCCESS)
					if (inDBCreateFile(szSFileName, sizeof (srCPACSettleBottom)) != VS_SUCCESS)
						ACTIVITY_LOG("Bottom fopen failed"); //return(VS_ERROR);

				memset (&srCPACSettleBottom, 0x00, sizeof(srCPACSettleBottom));
				srCPACSettleBottom.lnBottomCond= lnMiddleCondition;

				if (inDBWriteRecord(szSFileName, 1, (unsigned char *)&srCPACSettleBottom) < 0)
					ACTIVITY_LOG("Settle Bottom Failed");

				//inRecCnt++;
			}
		// #endif   /* TLFB */  (Made this feature as the part of CPAC Base Application)
             /*Saritha_b1..............End............Reprint Settlement Report */
    }
#endif /* CITI_PHIL */
//leo_nosourcesafe
#ifdef CITI_IND
    if (inGGCode() == SETTLE) {


    lnMiddleCondition = lnCPACMiddleCondition;


     //if (inPrintLines(&obPrinter, CPAC_SETTLEMENT_STATUS_START, CPAC_SETTLEMENT_STATUS_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
        //	return(VS_ERR);
    }
#endif /* CITI_IND */

#ifdef CITI_IND

		memcpy(&srRcpt.unFrm.srSubTotal.srTerm, &srTempRcpt.unFrm.srSubTotal.srTerm, sizeof(srRcpt.unFrm.srSubTotal.srTerm));

#endif

    return(VS_SUCCESS);
}



/*********************************************************************************************
* @func int | inCITISummaryReportOperation |
*
*       Print Totals Report Operation.
*
* @parm TRANSACTION_OBJECT * | pobTran |
*
* @rdesc return values.
* @flag int    |  VS_SUCCESS
* @flag int    |  VS_ERR
* @end

**********************************************************************************************/

int inCITISummaryReportOperation (TRANSACTION_OBJECT *pobTran)
{

/*    pdebug(("--inSummaryReportOperation--"));*/
#if CITI_PHIL
    lnCPACMiddleCondition=lnMiddleCondition;
#endif /* CITI_PHIL */

//leo_nosourcesafe
#ifdef CITI_IND
    lnCPACMiddleCondition=lnMiddleCondition;
#endif /* CITI_IND */

    if (inGetPrinterType() == NOPRINTER  && fGetEnablePrinter())
    {
        vdDisplayMessageFromFile( NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }
    //if (!fGetEnablePrinter())
    //    return(VS_SUCCESS);

    inGetReport1Template();

    return(inCITIPrintSummaryReport( &obPrinter, pobTran));
}

/*********************************************************************************************
* @func int | inCITIPrintSummaryReport |
*
*       Print Totals Report.
*
* @parm PRINTER_OBJECT * | pobPrinter |
* @parm TRANSACTION_OBJECT * | pobTran |
*
* @rdesc return values.
* @flag int    |  VS_SUCCESS
* @flag int    |  VS_ERR
* @end

**********************************************************************************************/

int inCITIPrintSummaryReport (PRINTER_OBJECT *pobPrinter, TRANSACTION_OBJECT *pobTran)
{
    char szDate[DATE_SIZE + 1];
    int     inStart, inStop, inNumberOfMerchants, inMerch = 0;
    int inHostIndex;
    int inReportTop = VS_TRUE;
//    CBT_ACCUM_VALUES srAccum; CPAC_LINT_REMOVED

#ifdef DOWNLOAD_MULTIPLE_LOGO
	inMultipleDownloadLogo(0);
#endif

/*     if ( fChkAllHostBatches(pobTran) )
    {
        vdDisplayMessageFromFile( BATCH_EMPTY_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }  Devil */
    if ( inGetHostTranCnt(pobTran) < 1 ) {
		vdDisplayMessageFromFile( BATCH_EMPTY_MSG, WARNING_MSG);
          //  return(BATCH_EMPTY_MSG);
     		 vdSGErrorMessage(0L);
        	return (VS_SUCCESS);
    	}

    inNumberOfMerchants = inSelectOneAllMID(pobTran,fGetMultiMerchPrompt());//1.4
    inHostIndex=inGetHostHandle(); //LENIN
    vdSetMerchantNum(inGlobalMerchantHandle);
    if (inNumberOfMerchants == inGetMITTotRecs())
    {
        inStart = 1;
        inStop = inGetMITTotRecs();
    }
    else if (inNumberOfMerchants == 1)
    {
        inStart = inGetMerchantNum();
        inStop = inGetMerchantNum();
    }
    else
    {
        inStart = 1;
        inStop = 0;
    }
		inMerch=inGetMerchantNum();;
    //for (inMerch = inStart; inMerch <= inStop; inMerch++)
    //{            // Commented by Lenin to support multi- merchant
        if (inLoadMITRec(inMerch-1) != VS_SUCCESS)
        {
            return(VS_ERR);
        }

        /* Get the total number of records in the batch */
        if (inGetDCBatchRecCnt(pobTran) == 0)
        {
            vdDisplayMessageFromFile( BATCH_EMPTY_MSG, WARNING_MSG);
            vdCloseDCBatch(pobTran); /* bb1 */
            /* loop back for next merchant */
            // continue; LENIN
            return (VS_ERR);
        }
        vdCloseDCBatch(pobTran); /* bb1 */

        if (fGetEnablePrinter())
		{
			vdDisplayAt(1,inImamLineNumber,"PRINTING ...", NO_CLEAR);
			//vdDisplayAt(1,7,"PRINTING....", NO_CLEAR);
            //vdDisplayAt(1,8,"                         ", NO_CLEAR);
		}

        if (inGGCode() == SETTLE)
        {
            vdGetDate(szDate,MMDDYY);
            strlcpy (pobTran->szSettDate, szDate, DATE_SIZE);
			//leo_nosourcesafe
#ifdef CITI_IND
				vdGetDate(srRcpt.szDate, YYMMDD);
				vdFormatCITIDate(srRcpt.szDate);
#endif /*CITI_IND*/
        }

    //LENIN    for (inHostIndex = 0; inHostIndex < MAX_HOSTS; inHostIndex++)
    // LENIN {
    // LENIN        vdSetCDTHostIndex (inHostIndex);

            if (inLoadDefaultHost (inHostIndex) != VS_SUCCESS) //1.4
                return (VS_ERR);

            if (inLoadDefaultCurrency (pobTran) != VS_SUCCESS)
                return (VS_ERR);

/*			inCBTGetAccum (pobTran, 1, srAccum, 1);  removed to remove the batch error message */
            /* Only print the report for independent host */

//Kelvin_F2 --- start: fix the bug for if single merchant, double header...
           // vdMakeReportHeader(pobTran);//saritha
           // inPrintReceiptHeader(pobTran); //saritha
//Kelvin_F2 --- end: fix the bug for if single merchant, double header...
				if ( fIsIndependentBatch ( inGetHostHandle() ))  // 1.4

/*            if (srHDTRec.shHostGroupRef == srHDTRec.inBatchIndex) sad_14 */
            {
                /* Print the overall totals */
				//kelvin_f2 Bug fix for handle decrease 29apr2002
                //inCPACPrintSummaryMiddle (pobPrinter, pobTran, &inReportTop, inNumberOfMerchants); /* mb1 */

				if (fGetImamReportPerCard()){
					if (inImamPrintSummaryMiddle(pobPrinter, pobTran, &inReportTop, inNumberOfMerchants) != VS_SUCCESS)
						return (VS_ERR);
				} else {
					if (inCITIPrintSummaryMiddle (pobPrinter, pobTran, &inReportTop, inNumberOfMerchants) != VS_SUCCESS)
						return (VS_ERR);
				}
            }
    //LENIN     } /* host loop */
        /* Print FORM_FEED  */
        if(inPrintLines(pobPrinter, CPAC_END_OF_REPORT_START, CPAC_END_OF_REPORT_END, NO_BL_LINE, 0x80000000) != VS_SUCCESS)
            return(VS_ERR);
            if (inGGCode() != SETTLE) {
		   if(inPrintLines(pobPrinter, 198 ,198  , NO_BL_LINE, 0L) != VS_SUCCESS)
            		return(VS_ERR);
            }

    //}  commented by Lenin to support multi host  /* merchant loop */

    return(VS_SUCCESS);
}




/*********************************************************************************************
* @func int | inCITIPrintSummaryMiddle |
*
*       Browse the Acummulators and print items with totals.
*
* @parm PRINTER_OBJECT * | pobPrinter |
* @parm TRANSACTION_OBJECT * | pobTran |
*
* @rdesc return values.
* @flag int    |  VS_SUCCESS
* @flag int    |  VS_ERR
* @end

**********************************************************************************************/


int inCITIPrintSummaryMiddle(PRINTER_OBJECT* pobPrinter,TRANSACTION_OBJECT* pobTran,int* pinReportTop,int inNumberOfMerchants) {
    //    int inHostIdx; CPAC_LINT_REMOVED
    int inNewHost;
	   int inPrintError=0;  //KiaSoon
    CARD_TOTS_REC srGrandTots;

#ifdef CITI_IND
    RCPT_FIELDS srTempRcpt;
#endif /* CITI_IND CPAC_LINT */

    /*   Saritha_b1...........Start............Reprint Settlement Report  */

    // #ifdef TLFB   (Made this feature as the part of CPAC Base Application)
    char szSFileName[FILENAME_SIZE + 1];
    int inRecCnt = 1;
    // #endif /*  TLFB  */  (Made this feature as the part of CPAC Base Application)

    /*   Saritha_b1............End.............Reprint Settlement Report  */

    int inIssuer = 0;
    int inIssuerCnt = 0;
    int inGrandIssuerCnt = 0;
    int inRetVal = 0;
    long lnRecNum = 0L;
    int inNegPos;
    char szCurSym[CUR_SYMBOL_SIZE + 1];
    long lnCount = 0L,
    lnAmount = 0L,
    lnTip = 0L,
    lnTotal = 0L,
    lnTax = 0L,
    lnSurCharge = 0L,
    lnCashBack = 0L;
    long lnDebitCount = 0L,
    lnCreditCount = 0L,
    lnAdjustCount = 0L,
    lnNetCount = 0L;
    long lnDebitAmount = 0L,
    lnCreditAmount = 0L,
    lnAdjustAmount = 0L,
    lnNetAmount = 0L;
    long lnSaleCount = 0L,
    lnRefundCount = 0L,
    lnVoidSaleCount = 0L,
    lnVoidRefundCount = 0L,
    lnTotalCount = 0L;
    double dbSaleAmount = 0.0,
    dbRefundAmount = 0.0,
    dbVoidSaleAmount = 0.0,
    dbVoidRefundAmount = 0.0,
    dbTotalAmount = 0.0;
    unsigned char ucIITTempRec[SIZE_IIT_REC + 1];


    double dbGrandSaleAmount = 0.0,
    dbGrandRefundAmount = 0.0,
    dbGrandVoidSaleAmount = 0.0,
    dbGrandVoidRefundAmount = 0.0,
    dbGrandTotalAmount = 0.0;
    long lnGrandSaleCount = 0L,
    lnGrandRefundCount = 0L,
    lnGrandVoidSaleCount = 0L,
    lnGrandVoidRefundCount = 0L,
    lnGrandTotalCount = 0L;

    long lnOfflineCount = 0L,
    lnGrandOfflineCount = 0L;
    long lnEPPSaleCount=0L,
    lnGrandEPPSaleCount=0L;
    double dbOfflineAmount = 0.0,
    dbGrandOfflineAmount = 0.0;
    double dbTipAmount = 0.0,
    dbGrandTipAmount = 0.0;
    double dbEPPSaleAmount=0.0,
    dbGrandEPPSaleAmount=0.0;

    char szFileName[FILENAME_SIZE + 1];
    DB_FILE srDBFPtr;
    ACCUM_REC srAccumRec;
    ACCUM_KEY srAccumKey;
    ACCUM_SKEY srAccumSKey;
    int inKeyIdx = 0;
    int inResult = 0;

    long lnAdjustNum = 0;

    FHANDLE hFHandle;
    ACCUM_SHIFT srASI;
    /* LENIN CPAC #if TBD_CPAC */
    //  IIT_REC srCPACIITRec; cpac_2.2a
    /* LENIN CPAC #endif  TBD_CPAC */

    //memset(&srRcpt, 0, sizeof(RCPT_FIELDS)); //leo_nov1400
    memset((char *) &srGrandTots, 0x00, (SIZE_CARD_TOTS_REC));
    /*  {
            srGrandTots.inTotalCnt = 0;
            srGrandTots.lnTotalAmt = 0L;
            srGrandTots.lnSaleAmt  = 0L;
            srGrandTots.lnTipAmt   = 0L;
            srGrandTots.lnTaxAmt   = 0L;
            srGrandTots.lnSurCharge   = 0L;
            srGrandTots.lnCashBack   = 0L;
           }
    */
    vdGetAccumFName(szFileName);
#ifdef CITI_PHIL
    if (inGGCode() == SETTLE) {
        if (lnCPACMiddleCondition & 0x02000000)
            lnAdjustNum = 1L;
    }
#endif /* CITI_PHIL */
    //leo_nosourcesafe
#ifdef CITI_IND
    if (inGGCode() == SETTLE) {
        if (lnCPACMiddleCondition & 0x02000000)
            lnAdjustNum = 1L;
    }
#endif /* CITI_IND */
    if (inOpenAccum(&srDBFPtr, szFileName) != VS_SUCCESS) {

        vdSGErrorMessage(BATCH_ERR_MSG);
        return(VS_ERR);
    }

    vdCPACSetSummaryMiddleCondition();

    /*  Read ASI File to use for determining if issuer accumulator has been updated */


    vdGetASIFName(szFileName);
    if ((hFHandle = open(szFileName, O_RDWR)) < 0) {
        if ((hFHandle = open(szFileName, O_CREAT | O_RDWR)) < 0)
            return(VS_ERR);

        memset((char *) &srASI, 0x00, SIZE_ACCUM_SHIFT);
    } else
        inResult = read(hFHandle, (char *) &srASI, SIZE_ACCUM_SHIFT);

    close(hFHandle);

    srAccumSKey.compare_func = inAccumCompFn;
    inNewHost = VS_TRUE;
    inIssuerCnt = 0;

    for (inIssuer = 0; inIssuer < TOTAL_ISSUERS; inIssuer++) {
#if 0
    if (srASI.srIssuer.fActiveAccum[inIssuer] == '\0')
        continue;

inGetIssuerRecord(inIssuer);
#ifdef CITI_IND
memcpy(&srTempRcpt.unFrm.srSubTotal.srTerm, &srRcpt.unFrm.srSubTotal.srTerm, sizeof(srRcpt.unFrm.srSubTotal.srTerm)); //leo_nov1300
#endif
strlcpy(srRcpt.unFrm.srSummary.srMid.szCType, srCPACIITRec.szIssuerLabel, CLABEL_SIZE);
#endif /* 0 */

        if ((inLoadIITRecFromStruct(inIssuer, ucIITTempRec)) == VS_ERR) {
            inCloseAccum(&srDBFPtr);
            vdSGErrorMessage(IIT_ERR_MSG21);
            return(VS_ERR);
        }

        if (srASI.srIssuer.fActiveAccum[inGetIssuerNumberFromStruct(ucIITTempRec)] == '\0')
            continue;
#ifdef CITI_IND
        memcpy(&srTempRcpt.unFrm.srSubTotal.srTerm, &srRcpt.unFrm.srSubTotal.srTerm, sizeof(srRcpt.unFrm.srSubTotal.srTerm)); //leo_nov1300

#endif
        strlcpy(srRcpt.unFrm.srSummary.srMid.szCType, szGetIssuerLabelFromStruct(ucIITTempRec), CLABEL_SIZE);


        //    srAccumKey.inIssuerNumber = inIssuer;
        //    srAccumSKey.accumKey.inIssuerNumber = inIssuer;
        srAccumKey.inIssuerNumber = inGetIssuerNumberFromStruct(ucIITTempRec);
        srAccumSKey.accumKey.inIssuerNumber = inGetIssuerNumberFromStruct(ucIITTempRec);
        /* If record does not exist then go to next issuer */
        inRetVal = inKeyReadAccum(&srDBFPtr, &srAccumRec, &srAccumKey, &srAccumSKey, &lnRecNum);
        if (inRetVal == VS_SUCCESS) {
            long2str(srRcpt.szBatchNum, (lnGetBatchNum() - lnAdjustNum));
            if (inNewHost) {
                if (*pinReportTop == VS_TRUE) {
                    vdMakeReportHeader(pobTran);
                    if (inGetMITTotRecs() == 1 || inNumberOfMerchants == 1) {
                        long2str(srRcpt.szBatchNum, (lnGetBatchNum() - lnAdjustNum));
                        //sprintf(srRcpt.szBatchNum, "%03ld", lnGetBatchNum());
                        //  strcpy (srRcpt.szBatchNum,pobTran->szBatchNum);/* Lenin */

                        inPrintReceiptHeader(pobTran);
                    } else {
                        long2str(srRcpt.szBatchNum, (lnGetBatchNum() - lnAdjustNum));
                        //sprintf(srRcpt.szBatchNum, "%03ld", lnGetBatchNum());
                        // if (inPrintLines(pobPrinter, REPORT_HEADER_START, REPORT_HEADER_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS)
                        //     return(VS_ERR);
                        //Kelvin_F2 --- start: fix the bug for if single merchant, double header...
                        //Kelvin_F2 Bug fix for handle decrease 29apr2002
                        //inPrintReceiptHeader(pobTran);
                        if (inPrintReceiptHeader(pobTran) != VS_SUCCESS) {
                            inCloseAccum(&srDBFPtr);
                            return(VS_ERR);
                        }
                        //Kelvin_F2 --- end: fix the bug for if single merchant, double header...
                    }
                }

                inNewHost = VS_FALSE;
                /* Header condition should not print report title except at top of report */
                vdCPACSetSummaryHeaderCondition(*pinReportTop, pobTran, VS_FALSE);
                *pinReportTop = VS_FALSE;

                strlcpy(srRcpt.szMerchantName, szGetMerchantText(), sizeof(srRcpt.szMerchantName));
                strlcpy(srRcpt.szHostName, szGetHostName(), sizeof(srRcpt.szHostName));
#ifdef CITI_PHIL
                //Kelvin_F2 --- start: no need to mask TID
#ifdef MASK_TID_AND_MID
                vdMaskCitiMTID();
#endif
                //Kelvin_F2 --- end: no need to mask TID
#endif /* CITI_PHIL */
                //leo_nosourcesafe
#ifdef CITI_IND
                vdGetDate(srRcpt.szDate, YYMMDD);
                vdFormatCITIDate(srRcpt.szDate);
#endif /*CITI_IND*/
                pad(srRcpt.szBatchNum, srRcpt.szBatchNum, '0', inGetBatchNumSize(), RIGHT); // Lenin 1.4
                if(!inPrintError)
   		{
                	if (inPrintLines(pobPrinter, CPAC_SUMMARY_TOP_START, CPAC_SUMMARY_TOP_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS) {
                		inPrintError=1;
                    //Kelvin_F2 Bug fix for handle decrease 29apr2002
                    //    return(VS_ERR);
                    //inCloseAccum(&srDBFPtr);//KiaSoon comment
                    //return(VS_ERR); //KiaSoon comment
               		}
		}


                /*Saritha_b1.............Start...........Amex SOC Printing */
#ifdef AMEX_SOC
                if (inGGOpCode() == SETTLE_OPERATION) {
                    strcpy(srRcpt.unFrm.srReceipt.szGenBuf2, (char *) srISO.pszField62);
                    if (strcmp(szGetHostFileName(), "AXAP") == 0) {
                    	 if(!inPrintError)
   			{
               
                        if (inPrintLines(&obPrinter, AMEX_SOC_PRINT_START, AMEX_SOC_PRINT_END, NO_BL_LINE, 4L) != VS_SUCCESS) {
                            //Kelvin_F2 Bug fix for handle decrease 29apr2002
                            //    return(VS_ERR);
                            //inCloseAccum(&srDBFPtr);Kia Soon
                            //return(VS_ERR); KiaSoon
                            inPrintError=1;
				}
			}
        	}
		#ifndef ICICI
               /*venu soc fix*/
		else
        	{
           		// If it is not AXAP, depend on condition line set in TPL file.
           		 if(!inPrintError)
   			{
               
           			if (inPrintLines(&obPrinter, AMEX_SOC_PRINT_START,AMEX_SOC_PRINT_END, NO_BL_LINE, 2L) != VS_SUCCESS)
                		{           //Kelvin_F2 Bug fix for handle decrease 29apr2002
					        //    return(VS_ERR);
							//inCloseAccum(&srDBFPtr);
							//return(VS_ERR); KiaSoon
							inPrintError=1;
				}
        		}
        	}
        	#endif  /* ICICI  */
                }

#endif  /*   AMEX_SOC */

                /* Saritha_b1.............End...........Amex SOC Printing */

                /*Saritha_b1.............Start...........Reprint Settlement Report */

                // #ifdef TLFB  (Made this feature as the part of CPAC Base Application)

                if (inGGCode() == SETTLE) {
                    vdGetReprintSettleFileName(szSFileName, CPAC_HEADER);

                    if (inDBFileExists(szSFileName) == VS_SUCCESS)
                        inDBRemoveFile(szSFileName);

                    if (inDBFileExists(szSFileName) != VS_SUCCESS)
                        if (inDBCreateFile(szSFileName, sizeof(srCPACSettleHeader)) != VS_SUCCESS)
                            ACTIVITY_LOG("HDR Fopen failed");//return(VS_ERROR);

                    memset(&srCPACSettleHeader, 0x00, sizeof(srCPACSettleHeader));

                    strcpy(srCPACSettleHeader.szDate, srRcpt.szDate);
                    strcpy(srCPACSettleHeader.szTime, srRcpt.szTime);
                    strcpy(srCPACSettleHeader.szMID, srRcpt.szMerchantId);
                    strcpy(srCPACSettleHeader.szTID, srRcpt.szTermId);
                    strcpy(srCPACSettleHeader.szBatchNum, srRcpt.szBatchNum);
                    strcpy(srCPACSettleHeader.szHostName, srRcpt.szHostName);
                    srCPACSettleHeader.lnHeaderCond = lnHeaderCondition;

#ifdef AMEX_SOC
                    strcpy(srCPACSettleHeader.szSOC, srRcpt.unFrm.srReceipt.szGenBuf2);
#endif /*  AMEX_SOC */

                    if (inDBWriteRecord(szSFileName, 1, (unsigned char *) &srCPACSettleHeader) < 0)
                        ACTIVITY_LOG("Hdr storage failed");
                }
                // #endif   /* TLFB */   (Made this feature as the part of CPAC Base Application)
                /*Saritha_b1..............End............Reprint Settlement Report */
            }
            /*  Use totals from record */


            lnSaleCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] ;

            lnRefundCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];

            lnVoidSaleCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[VOID_SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[VOID_SALE_TRAN];

            lnVoidRefundCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[VOID_REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[VOID_REFUND_TRAN];


            lnTotalCount = lnSaleCount + lnRefundCount + lnVoidSaleCount + lnVoidRefundCount;

            lnOfflineCount = srAccumRec.srTotals[CREDIT_CARD].dbCustom1[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbCustom1[SALE_TRAN] ;

              lnEPPSaleCount= srAccumRec.srTotals[CREDIT_CARD].dbCustom3[SALE_TRAN] +  srAccumRec.srTotals[DEBIT_CARD].dbCustom3[SALE_TRAN] ;


            /* lnCreditCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] ;
            lnDebitCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN]                          + srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];
              lnCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] +
                        srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];
            */


            dbSaleAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[SALE_TRAN];
            dbRefundAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[REFUND_TRAN];

            dbVoidSaleAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[VOID_SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[VOID_SALE_TRAN];

            dbVoidRefundAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[VOID_REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[VOID_REFUND_TRAN];
            dbTotalAmount = dbSaleAmount - dbRefundAmount;
            //-lnVoidSaleAmount;

            dbOfflineAmount = srAccumRec.srTotals[CREDIT_CARD].dbCustom2[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbCustom2[SALE_TRAN];
            dbTipAmount = srAccumRec.srTotals[CREDIT_CARD].dbTip[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbTip[SALE_TRAN];
		dbEPPSaleAmount=srAccumRec.srTotals[CREDIT_CARD].dbCustom4[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbCustom4[SALE_TRAN];
#ifdef CITI_PHIL
            if (lnSaleCount >= lnOfflineCount) {
                lnSaleCount -= lnOfflineCount;
                dbSaleAmount -= dbOfflineAmount;
			}
	    //jrd 05122005
          /*if (lnSaleCount >= lnEPPSaleCount){
				lnSaleCount-=lnEPPSaleCount;
				dbSaleAmount-=dbEPPSaleAmount;
			}*/

#ifdef  SHELL_FLEET
            lnSaleCount += lnOfflineCount;
            dbSaleAmount += dbOfflineAmount;
	lnSaleCount+=lnEPPSaleCount;
	dbSaleAmount+=dbEPPSaleAmount;

#endif /* SHELL_FLEET */
#endif /* CITI_PHIL */

            /* Set print line */

            sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_LD, lnSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szDebitCount, SUBSTITUTE_LD, lnRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustCount, SUBSTITUTE_LD, lnVoidSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szReversalCount, SUBSTITUTE_LD, lnVoidRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnTotalCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szShiftNumber, SUBSTITUTE_LD, lnOfflineCount);
		sprintf(srRcpt.unFrm.srSummary.srMid.szEPPSaleCount, SUBSTITUTE_LD, lnEPPSaleCount);

            /* Total Amount */
            vdDb2Str(dbSaleAmount, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
            vdDb2Str(dbRefundAmount, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
            vdDb2Str(dbVoidSaleAmount, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);

            vdDb2Str(dbVoidRefundAmount, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
            vdDb2Str(dbTotalAmount, srRcpt.unFrm.srSummary.srMid.szNetTotal);
            vdDb2Str(dbOfflineAmount, srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
            vdDb2Str(dbTipAmount, srRcpt.unFrm.srSummary.srMid.szCashBackTotal);
     vdDb2Str(dbEPPSaleAmount,srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal);
            //sprintf(srRcpt.unFrm.srSummary.srMid.szCreditTotal, SUBSTITUTE_LD, lnSaleAmount);
            //  sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD, lnRefundAmount);
            //  sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD, lnVoidSaleAmount);
            //   sprintf(srRcpt.unFrm.srSummary.srMid.szReversalTotal, SUBSTITUTE_LD, lnVoidRefundAmount);
            //   sprintf(srRcpt.unFrm.srSummary.srMid.szNetTotal, SUBSTITUTE_LD, lnTotalAmount);
            //  sprintf(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, SUBSTITUTE_LD, lnOfflineAmount);
            /* will put dollar sign in front */
            /* vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal);  */
            //vdPutDecPoint(srRcpt.unFrm.srSummary.srMid.szCreditTotal);
            /* Sale Amount (Base Amount)*/
            /* LENIN  sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD,
                 (lnAmount - lnTip - lnTax - lnSurCharge - lnCashBack)); */
            //vdPutDecPoint(srRcpt.unFrm.srSummary.srMid.szDebitTotal);
            /*Tip Amount */
            //sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD, lnTip);
            //vdPutDecPoint(srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
            /*CashBack Amount */
            //sprintf(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, SUBSTITUTE_LD, lnCashBack);
            //vdPutDecPoint(srRcpt.unFrm.srSummary.srMid.szCashBackTotal);
            // if (inPrintLines(pobPrinter, SUMMARY_TOP_START, SUMMARY_TOP_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS)
            //       return(VS_ERR);

            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szReversalTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szNetTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, VS_TRUE);
	      vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal, VS_TRUE);
            /*  KK removed these lines to avoid two '-' sumbols from the total.

                        if ((lnSaleAmount - lnRefundAmount)< -999999999L) {

                            vdGetCSTCurSymbol(szCurSym);
                            inNegPos=strlen(szCurSym);
                            srRcpt.unFrm.srSummary.srMid.szNetTotal[inNegPos]='-';

                         }

            */
            // inGetIssuerRecord(inIssuer, &srCPACIITRec);
            //strlcpy(srRcpt.unFrm.srSummary.srMid.szCType, srIDTRec.szIssuerLabel, CLABEL_SIZE);
            //vdGetIssuerLabel(srRcpt.unFrm.srSummary.srMid.szCType);

			{//LIEM Add to correct the calculation
				unsigned long lnImamTotal;
				lnImamTotal = atol(srRcpt.unFrm.srSummary.srMid.szNetCount) 
								- atol(srRcpt.unFrm.srSummary.srMid.szAdjustCount) 
								- atol(srRcpt.unFrm.srSummary.srMid.szReversalCount);
				sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnImamTotal);
			}

	#if 0

	if(inGetTipProcessing() ==1)
	{
            if (inPrintLines(pobPrinter, CPAC_SUMMARY_MIDDLE_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
            {           //Kelvin_F2 Bug fix for handle decrease 29apr2002
                //    return(VS_ERR);
                inCloseAccum(&srDBFPtr);
                return(VS_ERR);
            }
	}
	else
	{

	    if (inPrintLines(pobPrinter, CPAC_SUMMARY_MIDDLE_START, 180, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
	    {			//Kelvin_F2 Bug fix for handle decrease 29apr2002
				//	  return(VS_ERR);
				inCloseAccum(&srDBFPtr);
				return(VS_ERR);
	    }
	}
	#endif


		/* Changes made specific for CITI Malaysia */
/*
		if(shGetHostGroupRef() == 4)  //EPP HOST being selected.
		{
            		if(inPrintLines(pobPrinter, CPAC_SUMMARY_MIDDLE_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, 0x00000010L) != VS_SUCCESS)
			{
				inCloseAccum(&srDBFPtr);
				return(VS_ERR);
			}
		}
		else if(shGetHostGroupRef() == 5)   //CASH HOST being selected.
		{
			if(inPrintLines(pobPrinter, CPAC_SUMMARY_MIDDLE_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, 0x00000020L) != VS_SUCCESS)
			{
				inCloseAccum(&srDBFPtr);
				return(VS_ERR);
			}
		}
		else if(shGetHostGroupRef() == 6)   //CABK HOST being selected.
		{
			if(inPrintLines(pobPrinter, CPAC_SUMMARY_MIDDLE_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, 0x00000040L) != VS_SUCCESS)
			{
				inCloseAccum(&srDBFPtr);
				return(VS_ERR);
			}
		}
		else  //CITI or JCBI or DINC or AMEX being selected
*/
		{
			if(!inPrintError)
   			{
		
				if (inPrintLines(pobPrinter, CPAC_SUMMARY_MIDDLE_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, 1L) != VS_SUCCESS)
            			{
            				//inCloseAccum(&srDBFPtr);
					//return(VS_ERR);
					inPrintError=1; // KiaSoon
				}
			}
		}

            /* Changes made specific for CITI Malaysia */
            /*Saritha_b1.............Start...........Reprint Settlement Report */
            // #ifdef TLFB   (Made this feature as the part of CPAC Base Application)

            if (inGGCode() == SETTLE) {
				//jrd 02162005
				vdGetReprintSettleFileName(szSFileName, CPAC_BODY);

				// if (inDBFileExists(szSFileName) == VS_SUCCESS)  By kelvin_f2 multi_issuer
				if ((inDBFileExists(szSFileName) == VS_SUCCESS) && (inRecCnt == 1))
						inDBRemoveFile(szSFileName);


				if (inDBFileExists(szSFileName) != VS_SUCCESS)
					if (inDBCreateFile(szSFileName, sizeof (srCPACSettleMiddle)) != VS_SUCCESS)
							ACTIVITY_LOG("Bdy Fopen failed");//return(VS_ERROR);

                memset(&srCPACSettleMiddle, 0x00, sizeof(srCPACSettleMiddle));

                strcpy(srCPACSettleMiddle.szCardName, srRcpt.unFrm.srSummary.srMid.szCType);
                strcpy(srCPACSettleMiddle.szCreditCnt, srRcpt.unFrm.srSummary.srMid.szCreditCount);
                strcpy(srCPACSettleMiddle.szCreditTot, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
                strcpy(srCPACSettleMiddle.szDebitCnt, srRcpt.unFrm.srSummary.srMid.szDebitCount);
                strcpy(srCPACSettleMiddle.szDebitTot, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
                strcpy(srCPACSettleMiddle.szShiftNum, srRcpt.unFrm.srSummary.srMid.szShiftNumber);
		        strcpy(srCPACSettleMiddle.szShiftEPPSale, srRcpt.unFrm.srSummary.srMid.szEPPSaleCount);
                strcpy(srCPACSettleMiddle.szSurCharge, srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
                strcpy(srCPACSettleMiddle.szAdjCnt, srRcpt.unFrm.srSummary.srMid.szAdjustCount);
                strcpy(srCPACSettleMiddle.szAdjTot, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
                strcpy(srCPACSettleMiddle.szReversalCnt, srRcpt.unFrm.srSummary.srMid.szReversalCount);
                strcpy(srCPACSettleMiddle.szReversalTot, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
                strcpy(srCPACSettleMiddle.szNetCnt, srRcpt.unFrm.srSummary.srMid.szNetCount);
                strcpy(srCPACSettleMiddle.szNetTot, srRcpt.unFrm.srSummary.srMid.szNetTotal);
				//jrd 05162005
				srCPACSettleMiddle.lnMiddleCond = lnMiddleCondition;
/*  Comment
				if(shGetHostGroupRef() == 4)  //EPP HOST being selected.
				{
            		 		srCPACSettleMiddle.lnMiddleCond =  0x00000010L;
				}
				else if(shGetHostGroupRef() == 5)
						srCPACSettleMiddle.lnMiddleCond = 0x00000020L;

					else if(shGetHostGroupRef() == 6)
						 	srCPACSettleMiddle.lnMiddleCond = 0x00000040L;
						else
*/
				srCPACSettleMiddle.lnMiddleCond = 0x00000001L;
				//jrd 05162005
				if (inDBWriteRecord(szSFileName, inRecCnt, (unsigned char *)&srCPACSettleMiddle) < 0)
					ACTIVITY_LOG("Settle Middle Failed");

                inRecCnt++;
            }
            // #endif   /* TLFB */  (Made this feature as the part of CPAC Base Application)
            /*Saritha_b1..............End............Reprint Settlement Report
            //   if (act_kbd_pending_test(KEY_CANCEL)) (Saritha_b1 commented )
            //   return(VS_ESCAPE);     (Saritha_b1 commented )

            Accumulate totals */


            /*            srGrandTots.inTotalCnt += (int)(lnSaleCount+lnRefundCount+lnVoidSaleCount+lnVoidRefundCount);
                        srGrandTots.lnTotalAmt += dbTotalAmount;
                        srGrandTots.lnSaleAmt  += (dbSaleAmount);
                        srGrandTots.lnTipAmt   += dbTip;
                        srGrandTots.lnTaxAmt    += dbTax;
                        srGrandTots.lnSurCharge += dbSurCharge;
                        srGrandTots.lnCashBack  += dbCashBack;
            */

            lnGrandTotalCount += (int) (lnSaleCount + lnRefundCount + lnVoidSaleCount + lnVoidRefundCount + lnOfflineCount);

            lnGrandSaleCount += lnSaleCount;
            lnGrandRefundCount += lnRefundCount;
            lnGrandVoidSaleCount += lnVoidSaleCount;
            lnGrandVoidRefundCount += lnVoidRefundCount;
            lnGrandOfflineCount += lnOfflineCount;
	        lnGrandEPPSaleCount+=lnEPPSaleCount;

            dbGrandSaleAmount += dbSaleAmount;
            dbGrandRefundAmount += dbRefundAmount;
            dbGrandVoidSaleAmount += dbVoidSaleAmount;
            dbGrandVoidRefundAmount += dbVoidRefundAmount;
            dbGrandOfflineAmount += dbOfflineAmount;
            dbGrandTipAmount += dbTipAmount;
	        dbGrandEPPSaleAmount+=dbEPPSaleAmount;


            //( lnSaleCount+lnRefundCount+lnVoidSaleCount+lnVoidRefundCount);


            inIssuerCnt++;
            if (inIssuerCnt > inGrandIssuerCnt)
                inGrandIssuerCnt = inIssuerCnt;
#ifdef CITI_IND

            memcpy(&srRcpt.unFrm.srSubTotal.srTerm, &srTempRcpt.unFrm.srSubTotal.srTerm, sizeof(srRcpt.unFrm.srSubTotal.srTerm));

#endif
        }
    }
    inCloseAccum(&srDBFPtr);

    /* Print Grand Totals if more than one issuer */
    if (inIssuerCnt > 1) {
        if (inGrandIssuerCnt > 1) {
#if 0 /* LENIN */
    /* Set print line */
    sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_D,
        srGrandTots/*[TOTAL_ISSUERS]*/.inTotalCnt);
    /* Total Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szCreditTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnTotalAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal);
    /* Sale Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnSaleAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal);
    /*Tip Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnTipAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
    /*Tax Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szTaxTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnTaxAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szTaxTotal);
    /*Surcharge Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnSurCharge);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
    /*CashBack Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnCashBack);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCashBackTotal);
    /* Send VS_TRUE so FORM_FEED will print */
    #endif /* 0 */
#ifdef CITI_IND
            memcpy(&srTempRcpt.unFrm.srSubTotal.srTerm, &srRcpt.unFrm.srSubTotal.srTerm, sizeof(srRcpt.unFrm.srSubTotal.srTerm)); //leo_nov1300

#endif
            //            lnGrandTotalAmount=lnGrandSaleAmount-lnGrandRefundAmount+lnGrandVoidRefundAmount-lnGrandVoidSaleAmount;
            dbGrandTotalAmount=dbGrandSaleAmount-dbGrandRefundAmount+dbGrandOfflineAmount; //jrd+dbGrandEPPSaleAmount;

#ifdef CITI_IND

            dbGrandTotalAmount = dbGrandSaleAmount - dbGrandRefundAmount;

#endif /*CITI_IND*/
            //+lnGrandVoidRefundAmount-lnGrandVoidSaleAmount;
            //if (lnGrandSaleCount >= lnGrandOfflineCount){
            //  lnGrandSaleCount-=lnGrandOfflineCount;
            //  lnGrandSaleAmount-=lnGrandOfflineAmount;
            //}




            sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_LD, lnGrandSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szDebitCount, SUBSTITUTE_LD, lnGrandRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustCount, SUBSTITUTE_LD, lnGrandVoidSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szReversalCount, SUBSTITUTE_LD, lnGrandVoidRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnGrandTotalCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szShiftNumber, SUBSTITUTE_LD, lnGrandOfflineCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szEPPSaleCount, SUBSTITUTE_LD, lnGrandEPPSaleCount);


            vdDb2Str(dbGrandSaleAmount, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
            vdDb2Str(dbGrandRefundAmount, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
            vdDb2Str(dbGrandVoidSaleAmount, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);

            vdDb2Str(dbGrandVoidRefundAmount, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
            vdDb2Str(dbGrandTotalAmount, srRcpt.unFrm.srSummary.srMid.szNetTotal);
            vdDb2Str(dbGrandOfflineAmount, srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
            vdDb2Str(dbGrandTipAmount, srRcpt.unFrm.srSummary.srMid.szCashBackTotal);
		    vdDb2Str(dbGrandEPPSaleAmount, srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal);
            //sprintf(srRcpt.unFrm.srSummary.srMid.szCreditTotal, SUBSTITUTE_LD, lnGrandSaleAmount);
            //  sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD, lnGrandRefundAmount);
            //     sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD, lnGrandVoidSaleAmount);
            // sprintf(srRcpt.unFrm.srSummary.srMid.szReversalTotal, SUBSTITUTE_LD, lnGrandVoidRefundAmount);
            //   sprintf(srRcpt.unFrm.srSummary.srMid.szNetTotal, SUBSTITUTE_LD, lnGrandTotalAmount);
            //sprintf(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, SUBSTITUTE_LD, lnGrandOfflineAmount);


            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szReversalTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szNetTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal, VS_TRUE);


            if ((dbGrandSaleAmount - dbGrandRefundAmount) < -99999999999.00) {
                strcpy(szCurSym, szGetCurSymbol());

                inNegPos = strlen(szCurSym);
                srRcpt.unFrm.srSummary.srMid.szNetTotal[inNegPos] = '-';
            }
            vdCPACSetSummaryBottomCondition(pobTran, VS_TRUE, &srGrandTots/*[TOTAL_ISSUERS]*/);
			{//LIEM Add to correct the calculation
				unsigned long lnImamTotal;
				lnImamTotal = atol(srRcpt.unFrm.srSummary.srMid.szNetCount) 
								- atol(srRcpt.unFrm.srSummary.srMid.szAdjustCount) 
								- atol(srRcpt.unFrm.srSummary.srMid.szReversalCount);
				sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnImamTotal);
			}

            if (inPrintLines(pobPrinter, CPAC_GRANT_TOTAL_LABEL_START, CPAC_GRANT_TOTAL_LABEL_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
                return(VS_ERR);
            //Kelvin_F2 --- start: use CPAC_SUMMARY_BOTTOM_START and CPAC_SUMMARY_BOTTOM_END
            // if (inPrintLines(pobPrinter, SUMMARY_BOTTOM_START, SUMMARY_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)

            //if (inPrintLines(pobPrinter, CPAC_SUMMARY_BOTTOM_START, CPAC_SUMMARY_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)


#if 0
if(inGetTipProcessing() == 1)
{
            if (inPrintLines(pobPrinter, CPAC_SUMMARY_BOTTOM_START, CPAC_SUMMARY_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
                //Kelvin_F2 --- start: use CPAC_SUMMARY_BOTTOM_START and CPAC_SUMMARY_BOTTOM_END
                return(VS_ERR);
}
else
{
	if (inPrintLines(pobPrinter, CPAC_SUMMARY_BOTTOM_START, 194, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
				//Kelvin_F2 --- start: use CPAC_SUMMARY_BOTTOM_START and CPAC_SUMMARY_BOTTOM_END
					return(VS_ERR);
}
#endif
            if (inPrintLines(pobPrinter, CPAC_SUMMARY_BOTTOM_START, CPAC_SUMMARY_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
			//Kelvin_F2 --- start: use CPAC_SUMMARY_BOTTOM_START and CPAC_SUMMARY_BOTTOM_END
                return(VS_ERR);


            /*Saritha_b1.............Start...........Reprint Settlement Report */
            // #ifdef TLFB  (Made this feature as the part of CPAC Base Application)

            if (inGGCode() == SETTLE) {
                memset(&srCPACSettleMiddle, 0x00, sizeof(srCPACSettleMiddle));
                strcpy(srCPACSettleMiddle.szCardName, srRcpt.unFrm.srSummary.srMid.szCType);
                strcpy(srCPACSettleMiddle.szCreditCnt, srRcpt.unFrm.srSummary.srMid.szCreditCount);
                strcpy(srCPACSettleMiddle.szCreditTot, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
                strcpy(srCPACSettleMiddle.szDebitCnt, srRcpt.unFrm.srSummary.srMid.szDebitCount);
                strcpy(srCPACSettleMiddle.szDebitTot, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
                strcpy(srCPACSettleMiddle.szShiftNum, srRcpt.unFrm.srSummary.srMid.szShiftNumber);
				strcpy(srCPACSettleMiddle.szShiftEPPSale, srRcpt.unFrm.srSummary.srMid.szEPPSaleCount);
                strcpy(srCPACSettleMiddle.szSurCharge, srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
                strcpy(srCPACSettleMiddle.szAdjCnt, srRcpt.unFrm.srSummary.srMid.szAdjustCount);
                strcpy(srCPACSettleMiddle.szAdjTot, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
                strcpy(srCPACSettleMiddle.szReversalCnt, srRcpt.unFrm.srSummary.srMid.szReversalCount);
                strcpy(srCPACSettleMiddle.szReversalTot, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
                strcpy(srCPACSettleMiddle.szNetCnt, srRcpt.unFrm.srSummary.srMid.szNetCount);
                strcpy(srCPACSettleMiddle.szNetTot, srRcpt.unFrm.srSummary.srMid.szNetTotal);
                srCPACSettleMiddle.lnMiddleCond = lnBottomCondition;
				//jrd 05162005
				if (inDBFileExists(szSFileName) == VS_SUCCESS)
					if (inDBWriteRecord(szSFileName, inRecCnt, (unsigned char *)&srCPACSettleMiddle) < 0)
                        ACTIVITY_LOG("Settle Middle Failed");
            }
            // #endif   /* TLFB */  (Made this feature as the part of CPAC Base Application)
            /*Saritha_b1..............End............Reprint Settlement Report */
        }
    }
#if CITI_PHIL
    if (inGGCode() == SETTLE) {
        lnMiddleCondition = lnCPACMiddleCondition;


        if (inPrintLines(&obPrinter, CPAC_SETTLEMENT_STATUS_START, CPAC_SETTLEMENT_STATUS_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
            return(VS_ERR);

        /*Saritha_b1.............Start...........Reprint Settlement Report */
        // #ifdef TLFB  (Made this feature as the part of CPAC Base Application)
        if (inGGCode() == SETTLE) {
            vdGetReprintSettleFileName(szSFileName, CPAC_FOOTER);

            if (inDBFileExists(szSFileName) == VS_SUCCESS)
                inDBRemoveFile(szSFileName);

            if (inDBFileExists(szSFileName) != VS_SUCCESS)
                if (inDBCreateFile(szSFileName, sizeof(srCPACSettleBottom)) != VS_SUCCESS)
                    ACTIVITY_LOG("Bottom fopen failed"); //return(VS_ERROR);

            memset(&srCPACSettleBottom, 0x00, sizeof(srCPACSettleBottom));
            srCPACSettleBottom.lnBottomCond = lnMiddleCondition;

            if (inDBWriteRecord(szSFileName, 1, (unsigned char *) &srCPACSettleBottom) < 0)
                ACTIVITY_LOG("Settle Bottom Failed");

            //inRecCnt++;
        }
        // #endif   /* TLFB */  (Made this feature as the part of CPAC Base Application)
        /*Saritha_b1..............End............Reprint Settlement Report */
    }
#endif /* CITI_PHIL */
    //leo_nosourcesafe
#ifdef CITI_IND
    if (inGGCode() == SETTLE) {
        lnMiddleCondition = lnCPACMiddleCondition;


        if (inPrintLines(&obPrinter, CPAC_SETTLEMENT_STATUS_START, CPAC_SETTLEMENT_STATUS_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
            return(VS_ERR);
    }
#endif /* CITI_IND */

#ifdef CITI_IND

    memcpy(&srRcpt.unFrm.srSubTotal.srTerm, &srTempRcpt.unFrm.srSubTotal.srTerm, sizeof(srRcpt.unFrm.srSubTotal.srTerm));

#endif

     if(inPrintError!=0)  //added by KiaSoon: To fix Reprint settlement error
       return VS_ERR;
    else   
       return(VS_SUCCESS);
}

int inImamPrintSummaryMiddle(PRINTER_OBJECT* pobPrinter,TRANSACTION_OBJECT* pobTran,int* pinReportTop,int inNumberOfMerchants) 
{
    int inNewHost;
	int inPrintError=0;  //KiaSoon
    CARD_TOTS_REC srGrandTots;

    char szSFileName[FILENAME_SIZE + 1];
    int inRecCnt = 1;
    int inIssuer = 0;
    int inIssuerCnt = 0;
    int inGrandIssuerCnt = 0;
    int inRetVal = 0;
    long lnRecNum = 0L;
    int inNegPos;
    char szCurSym[CUR_SYMBOL_SIZE + 1];
    long lnCount = 0L,
    lnAmount = 0L,
    lnTip = 0L,
    lnTotal = 0L,
    lnTax = 0L,
    lnSurCharge = 0L,
    lnCashBack = 0L;
    long lnDebitCount = 0L,
    lnCreditCount = 0L,
    lnAdjustCount = 0L,
    lnNetCount = 0L;
    long lnDebitAmount = 0L,
    lnCreditAmount = 0L,
    lnAdjustAmount = 0L,
    lnNetAmount = 0L;
    long lnSaleCount = 0L,
    lnRefundCount = 0L,
    lnVoidSaleCount = 0L,
    lnVoidRefundCount = 0L,
    lnTotalCount = 0L;
    double dbSaleAmount = 0.0,
    dbRefundAmount = 0.0,
    dbVoidSaleAmount = 0.0,
    dbVoidRefundAmount = 0.0,
    dbTotalAmount = 0.0;
    //unsigned char ucIITTempRec[SIZE_IIT_REC + 1];
	unsigned char ucIITTempRec[SIZE_CDT_REC + 1];

    double dbGrandSaleAmount = 0.0,
    dbGrandRefundAmount = 0.0,
    dbGrandVoidSaleAmount = 0.0,
    dbGrandVoidRefundAmount = 0.0,
    dbGrandTotalAmount = 0.0;
    long lnGrandSaleCount = 0L,
    lnGrandRefundCount = 0L,
    lnGrandVoidSaleCount = 0L,
    lnGrandVoidRefundCount = 0L,
    lnGrandTotalCount = 0L;

    long lnOfflineCount = 0L,
    lnGrandOfflineCount = 0L;
    long lnEPPSaleCount=0L,
    lnGrandEPPSaleCount=0L;
    double dbOfflineAmount = 0.0,
    dbGrandOfflineAmount = 0.0;
    double dbTipAmount = 0.0,
    dbGrandTipAmount = 0.0;
    double dbEPPSaleAmount=0.0,
    dbGrandEPPSaleAmount=0.0;

    char szFileName[FILENAME_SIZE + 1];
    DB_FILE srDBFPtr;
    ACCUM_REC srAccumRec;
    ACCUM_KEY srAccumKey;
    ACCUM_SKEY srAccumSKey;
    int inKeyIdx = 0;
    int inResult = 0;

    long lnAdjustNum = 0;
	int inImamCDTTotal =0;

    FHANDLE hFHandle;
    ACCUM_SHIFT srASI;
	LOG_PRINTFF((0x08L, "==inImamCPACPrintSummaryMiddle=="));

	memset((char *) &srGrandTots, 0x00, (SIZE_CARD_TOTS_REC));
    vdGetAccumFName(szFileName);

    if (inGGCode() == SETTLE) {
        if (lnCPACMiddleCondition & 0x02000000)
            lnAdjustNum = 1L;
    }
    if (inOpenAccum(&srDBFPtr, szFileName) != VS_SUCCESS) {
        vdSGErrorMessage(BATCH_ERR_MSG);
        return(VS_ERR);
    }
    vdCPACSetSummaryMiddleCondition();

    /*  Read ASI File to use for determining if issuer accumulator has been updated */
    vdGetASIFName(szFileName);
    if ((hFHandle = open(szFileName, O_RDWR)) < 0) {
        if ((hFHandle = open(szFileName, O_CREAT | O_RDWR)) < 0)
            return(VS_ERR);

        memset((char *) &srASI, 0x00, SIZE_ACCUM_SHIFT);
    } else {
        inResult = read(hFHandle, (char *) &srASI, SIZE_ACCUM_SHIFT);
	}
    close(hFHandle);

    srAccumSKey.compare_func = inAccumCompFn;
    inNewHost = VS_TRUE;
    inIssuerCnt = 0;

	inImamCDTTotal = inGetCDTTotRecs();
    for (inIssuer = 0; inIssuer < inImamCDTTotal; inIssuer++) {
        if ((inLoadCDTRecFromStruct(inIssuer, ucIITTempRec)) == VS_ERR) {
            inCloseAccum(&srDBFPtr);
            vdSGErrorMessage(IIT_ERR_MSG21);
            return(VS_ERR);
        }
        if (srASI.srIssuer.fActiveAccum[inGetImamCDTIndexFromStruct(ucIITTempRec)] == '\0')
            continue;
		strlcpy(srRcpt.unFrm.srSummary.srMid.szCType, szGetCardLabelFromStruct(ucIITTempRec), CLABEL_SIZE);

        srAccumKey.inIssuerNumber = inGetImamCDTIndexFromStruct(ucIITTempRec);
        srAccumSKey.accumKey.inIssuerNumber = inGetImamCDTIndexFromStruct(ucIITTempRec);
        /* If record does not exist then go to next issuer */
        inRetVal = inKeyReadAccum(&srDBFPtr, &srAccumRec, &srAccumKey, &srAccumSKey, &lnRecNum);
        if (inRetVal == VS_SUCCESS) {
            long2str(srRcpt.szBatchNum, (lnGetBatchNum() - lnAdjustNum));
            if (inNewHost) {
                if (*pinReportTop == VS_TRUE) {
                    vdMakeReportHeader(pobTran);
                    if (inGetMITTotRecs() == 1 || inNumberOfMerchants == 1) {
                        long2str(srRcpt.szBatchNum, (lnGetBatchNum() - lnAdjustNum));
                        inPrintReceiptHeader(pobTran);
                    } else {
                        long2str(srRcpt.szBatchNum, (lnGetBatchNum() - lnAdjustNum));
                        if (inPrintReceiptHeader(pobTran) != VS_SUCCESS) {
                            inCloseAccum(&srDBFPtr);
                            return(VS_ERR);
                        }
                    }
                }

                inNewHost = VS_FALSE;
                vdCPACSetSummaryHeaderCondition(*pinReportTop, pobTran, VS_FALSE);
                *pinReportTop = VS_FALSE;

                strlcpy(srRcpt.szMerchantName, szGetMerchantText(), sizeof(srRcpt.szMerchantName));
                strlcpy(srRcpt.szHostName, szGetHostName(), sizeof(srRcpt.szHostName));

#ifdef MASK_TID_AND_MID
                vdMaskCitiMTID();
#endif
                pad(srRcpt.szBatchNum, srRcpt.szBatchNum, '0', inGetBatchNumSize(), RIGHT); // Lenin 1.4
                if(!inPrintError) {
                	if (inPrintLines(pobPrinter, CPAC_SUMMARY_TOP_START, CPAC_SUMMARY_TOP_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS) {
                		inPrintError=1;
               		}
				}

                /*Saritha_b1.............Start...........Amex SOC Printing */
#ifdef AMEX_SOC
                if (inGGOpCode() == SETTLE_OPERATION) {
                    strcpy(srRcpt.unFrm.srReceipt.szGenBuf2, (char *) srISO.pszField62);
                    if (strcmp(szGetHostFileName(), "AXAP") == 0) {
                    	 if(!inPrintError) {
							if (inPrintLines(&obPrinter, AMEX_SOC_PRINT_START, AMEX_SOC_PRINT_END, NO_BL_LINE, 4L) != VS_SUCCESS) {
								inPrintError=1;
							}
						}
        			}
#ifndef ICICI
					/*venu soc fix*/
				else {
           			// If it is not AXAP, depend on condition line set in TPL file.
           			if(!inPrintError) {
           				if (inPrintLines(&obPrinter, AMEX_SOC_PRINT_START,AMEX_SOC_PRINT_END, NO_BL_LINE, 2L) != VS_SUCCESS){
							inPrintError=1;
						}
        			}
        		}
#endif  /* ICICI  */
			}

#endif  /*   AMEX_SOC */

            if (inGGCode() == SETTLE) {
				vdGetReprintSettleFileName(szSFileName, CPAC_HEADER);
                if (inDBFileExists(szSFileName) == VS_SUCCESS)
					inDBRemoveFile(szSFileName);
                if (inDBFileExists(szSFileName) != VS_SUCCESS)
                    if (inDBCreateFile(szSFileName, sizeof(srCPACSettleHeader)) != VS_SUCCESS)
						ACTIVITY_LOG("HDR Fopen failed");//return(VS_ERROR);

				memset(&srCPACSettleHeader, 0x00, sizeof(srCPACSettleHeader));
                strcpy(srCPACSettleHeader.szDate, srRcpt.szDate);
                strcpy(srCPACSettleHeader.szTime, srRcpt.szTime);
                strcpy(srCPACSettleHeader.szMID, srRcpt.szMerchantId);
                strcpy(srCPACSettleHeader.szTID, srRcpt.szTermId);
                strcpy(srCPACSettleHeader.szBatchNum, srRcpt.szBatchNum);
                strcpy(srCPACSettleHeader.szHostName, srRcpt.szHostName);
                srCPACSettleHeader.lnHeaderCond = lnHeaderCondition;
#ifdef AMEX_SOC
                strcpy(srCPACSettleHeader.szSOC, srRcpt.unFrm.srReceipt.szGenBuf2);
#endif /*  AMEX_SOC */
                if (inDBWriteRecord(szSFileName, 1, (unsigned char *) &srCPACSettleHeader) < 0)
					ACTIVITY_LOG("Hdr storage failed");
			}
		}
        /*  Use totals from record */

        lnSaleCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] ;
        lnRefundCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];
        lnVoidSaleCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[VOID_SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[VOID_SALE_TRAN];
        lnVoidRefundCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[VOID_REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[VOID_REFUND_TRAN];
        lnTotalCount = lnSaleCount + lnRefundCount + lnVoidSaleCount + lnVoidRefundCount;
        lnOfflineCount = srAccumRec.srTotals[CREDIT_CARD].dbCustom1[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbCustom1[SALE_TRAN] ;
        lnEPPSaleCount= srAccumRec.srTotals[CREDIT_CARD].dbCustom3[SALE_TRAN] +  srAccumRec.srTotals[DEBIT_CARD].dbCustom3[SALE_TRAN] ;
        dbSaleAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[SALE_TRAN];
        dbRefundAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[REFUND_TRAN];
        dbVoidSaleAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[VOID_SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[VOID_SALE_TRAN];
        dbVoidRefundAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[VOID_REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[VOID_REFUND_TRAN];
        dbTotalAmount = dbSaleAmount - dbRefundAmount;
        //-lnVoidSaleAmount;
        dbOfflineAmount = srAccumRec.srTotals[CREDIT_CARD].dbCustom2[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbCustom2[SALE_TRAN];
        dbTipAmount = srAccumRec.srTotals[CREDIT_CARD].dbTip[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbTip[SALE_TRAN];
		dbEPPSaleAmount=srAccumRec.srTotals[CREDIT_CARD].dbCustom4[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbCustom4[SALE_TRAN];
#ifdef CITI_PHIL
        if (lnSaleCount >= lnOfflineCount) {
			lnSaleCount -= lnOfflineCount;
            dbSaleAmount -= dbOfflineAmount;
		}
#ifdef  SHELL_FLEET
        lnSaleCount += lnOfflineCount;
        dbSaleAmount += dbOfflineAmount;
		lnSaleCount+=lnEPPSaleCount;
		dbSaleAmount+=dbEPPSaleAmount;
#endif /* SHELL_FLEET */
#endif /* CITI_PHIL */
        /* Set print line */
        sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_LD, lnSaleCount);
        sprintf(srRcpt.unFrm.srSummary.srMid.szDebitCount, SUBSTITUTE_LD, lnRefundCount);
        sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustCount, SUBSTITUTE_LD, lnVoidSaleCount);
        sprintf(srRcpt.unFrm.srSummary.srMid.szReversalCount, SUBSTITUTE_LD, lnVoidRefundCount);
        sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnTotalCount);
        sprintf(srRcpt.unFrm.srSummary.srMid.szShiftNumber, SUBSTITUTE_LD, lnOfflineCount);
		sprintf(srRcpt.unFrm.srSummary.srMid.szEPPSaleCount, SUBSTITUTE_LD, lnEPPSaleCount);

        /* Total Amount */
        vdDb2Str(dbSaleAmount, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
        vdDb2Str(dbRefundAmount, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
        vdDb2Str(dbVoidSaleAmount, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
        vdDb2Str(dbVoidRefundAmount, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
        vdDb2Str(dbTotalAmount, srRcpt.unFrm.srSummary.srMid.szNetTotal);
        vdDb2Str(dbOfflineAmount, srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
        vdDb2Str(dbTipAmount, srRcpt.unFrm.srSummary.srMid.szCashBackTotal);
	    vdDb2Str(dbEPPSaleAmount,srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal);

        vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal, VS_TRUE);
        vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal, VS_TRUE);
        vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, VS_TRUE);
        vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szReversalTotal, VS_TRUE);
        vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szNetTotal, VS_TRUE);
        vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, VS_TRUE);
        vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, VS_TRUE);
	    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal, VS_TRUE);

		{//LIEM Add to correct the calculation
			unsigned long lnImamTotal;
			lnImamTotal = atol(srRcpt.unFrm.srSummary.srMid.szNetCount) 
							- atol(srRcpt.unFrm.srSummary.srMid.szAdjustCount) 
							- atol(srRcpt.unFrm.srSummary.srMid.szReversalCount);
			sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnImamTotal);
		}
		{
			if(!inPrintError) {
				if (inPrintLines(pobPrinter, CPAC_SUMMARY_MIDDLE_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, 1L) != VS_SUCCESS) {
					inPrintError=1; // KiaSoon
				}
			}
		}

        if (inGGCode() == SETTLE) {
			//jrd 02162005
			vdGetReprintSettleFileName(szSFileName, CPAC_BODY);
			// if (inDBFileExists(szSFileName) == VS_SUCCESS)  By kelvin_f2 multi_issuer
			if ((inDBFileExists(szSFileName) == VS_SUCCESS) && (inRecCnt == 1))
				inDBRemoveFile(szSFileName);

			if (inDBFileExists(szSFileName) != VS_SUCCESS)
				if (inDBCreateFile(szSFileName, sizeof (srCPACSettleMiddle)) != VS_SUCCESS)
					ACTIVITY_LOG("Bdy Fopen failed");//return(VS_ERROR);

            memset(&srCPACSettleMiddle, 0x00, sizeof(srCPACSettleMiddle));
            strcpy(srCPACSettleMiddle.szCardName, srRcpt.unFrm.srSummary.srMid.szCType);
            strcpy(srCPACSettleMiddle.szCreditCnt, srRcpt.unFrm.srSummary.srMid.szCreditCount);
            strcpy(srCPACSettleMiddle.szCreditTot, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
            strcpy(srCPACSettleMiddle.szDebitCnt, srRcpt.unFrm.srSummary.srMid.szDebitCount);
            strcpy(srCPACSettleMiddle.szDebitTot, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
            strcpy(srCPACSettleMiddle.szShiftNum, srRcpt.unFrm.srSummary.srMid.szShiftNumber);
	        strcpy(srCPACSettleMiddle.szShiftEPPSale, srRcpt.unFrm.srSummary.srMid.szEPPSaleCount);
            strcpy(srCPACSettleMiddle.szSurCharge, srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
            strcpy(srCPACSettleMiddle.szAdjCnt, srRcpt.unFrm.srSummary.srMid.szAdjustCount);
            strcpy(srCPACSettleMiddle.szAdjTot, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
            strcpy(srCPACSettleMiddle.szReversalCnt, srRcpt.unFrm.srSummary.srMid.szReversalCount);
            strcpy(srCPACSettleMiddle.szReversalTot, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
            strcpy(srCPACSettleMiddle.szNetCnt, srRcpt.unFrm.srSummary.srMid.szNetCount);
            strcpy(srCPACSettleMiddle.szNetTot, srRcpt.unFrm.srSummary.srMid.szNetTotal);
			//jrd 05162005
			srCPACSettleMiddle.lnMiddleCond = lnMiddleCondition;
			srCPACSettleMiddle.lnMiddleCond = 0x00000001L;
			//jrd 05162005
			if (inDBWriteRecord(szSFileName, inRecCnt, (unsigned char *)&srCPACSettleMiddle) < 0)
				ACTIVITY_LOG("Settle Middle Failed");
                inRecCnt++;
            }
            lnGrandTotalCount += (int) (lnSaleCount + lnRefundCount + lnVoidSaleCount + lnVoidRefundCount + lnOfflineCount);

            lnGrandSaleCount += lnSaleCount;
            lnGrandRefundCount += lnRefundCount;
            lnGrandVoidSaleCount += lnVoidSaleCount;
            lnGrandVoidRefundCount += lnVoidRefundCount;
            lnGrandOfflineCount += lnOfflineCount;
	        lnGrandEPPSaleCount+=lnEPPSaleCount;

            dbGrandSaleAmount += dbSaleAmount;
            dbGrandRefundAmount += dbRefundAmount;
            dbGrandVoidSaleAmount += dbVoidSaleAmount;
            dbGrandVoidRefundAmount += dbVoidRefundAmount;
            dbGrandOfflineAmount += dbOfflineAmount;
            dbGrandTipAmount += dbTipAmount;
	        dbGrandEPPSaleAmount+=dbEPPSaleAmount;
            //( lnSaleCount+lnRefundCount+lnVoidSaleCount+lnVoidRefundCount);

            inIssuerCnt++;
            if (inIssuerCnt > inGrandIssuerCnt)
                inGrandIssuerCnt = inIssuerCnt;
        }
    }
    inCloseAccum(&srDBFPtr);
    /* Print Grand Totals if more than one issuer */
    if (inIssuerCnt > 1) {
        if (inGrandIssuerCnt > 1) {
            dbGrandTotalAmount=dbGrandSaleAmount-dbGrandRefundAmount+dbGrandOfflineAmount; //jrd+dbGrandEPPSaleAmount;
            sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_LD, lnGrandSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szDebitCount, SUBSTITUTE_LD, lnGrandRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustCount, SUBSTITUTE_LD, lnGrandVoidSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szReversalCount, SUBSTITUTE_LD, lnGrandVoidRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnGrandTotalCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szShiftNumber, SUBSTITUTE_LD, lnGrandOfflineCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szEPPSaleCount, SUBSTITUTE_LD, lnGrandEPPSaleCount);

            vdDb2Str(dbGrandSaleAmount, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
            vdDb2Str(dbGrandRefundAmount, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
            vdDb2Str(dbGrandVoidSaleAmount, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);

            vdDb2Str(dbGrandVoidRefundAmount, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
            vdDb2Str(dbGrandTotalAmount, srRcpt.unFrm.srSummary.srMid.szNetTotal);
            vdDb2Str(dbGrandOfflineAmount, srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
            vdDb2Str(dbGrandTipAmount, srRcpt.unFrm.srSummary.srMid.szCashBackTotal);
		    vdDb2Str(dbGrandEPPSaleAmount, srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal);

            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szReversalTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szNetTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal, VS_TRUE);

            if ((dbGrandSaleAmount - dbGrandRefundAmount) < -99999999999.00) {
                strcpy(szCurSym, szGetCurSymbol());
                inNegPos = strlen(szCurSym);
                srRcpt.unFrm.srSummary.srMid.szNetTotal[inNegPos] = '-';
            }
            vdCPACSetSummaryBottomCondition(pobTran, VS_TRUE, &srGrandTots/*[TOTAL_ISSUERS]*/);
			{//LIEM Add to correct the calculation
				unsigned long lnImamTotal;
				lnImamTotal = atol(srRcpt.unFrm.srSummary.srMid.szNetCount) 
								- atol(srRcpt.unFrm.srSummary.srMid.szAdjustCount) 
								- atol(srRcpt.unFrm.srSummary.srMid.szReversalCount);
				sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnImamTotal);
			}

            if (inPrintLines(pobPrinter, CPAC_GRANT_TOTAL_LABEL_START, CPAC_GRANT_TOTAL_LABEL_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
                return(VS_ERR);

			if (inPrintLines(pobPrinter, CPAC_SUMMARY_BOTTOM_START, CPAC_SUMMARY_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
			//Kelvin_F2 --- start: use CPAC_SUMMARY_BOTTOM_START and CPAC_SUMMARY_BOTTOM_END
                return(VS_ERR);

            if (inGGCode() == SETTLE) {
                memset(&srCPACSettleMiddle, 0x00, sizeof(srCPACSettleMiddle));
                strcpy(srCPACSettleMiddle.szCardName, srRcpt.unFrm.srSummary.srMid.szCType);
                strcpy(srCPACSettleMiddle.szCreditCnt, srRcpt.unFrm.srSummary.srMid.szCreditCount);
                strcpy(srCPACSettleMiddle.szCreditTot, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
                strcpy(srCPACSettleMiddle.szDebitCnt, srRcpt.unFrm.srSummary.srMid.szDebitCount);
                strcpy(srCPACSettleMiddle.szDebitTot, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
                strcpy(srCPACSettleMiddle.szShiftNum, srRcpt.unFrm.srSummary.srMid.szShiftNumber);
				strcpy(srCPACSettleMiddle.szShiftEPPSale, srRcpt.unFrm.srSummary.srMid.szEPPSaleCount);
                strcpy(srCPACSettleMiddle.szSurCharge, srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
                strcpy(srCPACSettleMiddle.szAdjCnt, srRcpt.unFrm.srSummary.srMid.szAdjustCount);
                strcpy(srCPACSettleMiddle.szAdjTot, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
                strcpy(srCPACSettleMiddle.szReversalCnt, srRcpt.unFrm.srSummary.srMid.szReversalCount);
                strcpy(srCPACSettleMiddle.szReversalTot, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
                strcpy(srCPACSettleMiddle.szNetCnt, srRcpt.unFrm.srSummary.srMid.szNetCount);
                strcpy(srCPACSettleMiddle.szNetTot, srRcpt.unFrm.srSummary.srMid.szNetTotal);
                srCPACSettleMiddle.lnMiddleCond = lnBottomCondition;
				//jrd 05162005
				if (inDBFileExists(szSFileName) == VS_SUCCESS)
					if (inDBWriteRecord(szSFileName, inRecCnt, (unsigned char *)&srCPACSettleMiddle) < 0)
                        ACTIVITY_LOG("Settle Middle Failed");
            }
        }
    }
#if CITI_PHIL
    if (inGGCode() == SETTLE) {
        lnMiddleCondition = lnCPACMiddleCondition;

        if (inPrintLines(&obPrinter, CPAC_SETTLEMENT_STATUS_START, CPAC_SETTLEMENT_STATUS_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
            return(VS_ERR);

        /*Saritha_b1.............Start...........Reprint Settlement Report */
        // #ifdef TLFB  (Made this feature as the part of CPAC Base Application)
        if (inGGCode() == SETTLE) {
            vdGetReprintSettleFileName(szSFileName, CPAC_FOOTER);

            if (inDBFileExists(szSFileName) == VS_SUCCESS)
                inDBRemoveFile(szSFileName);

            if (inDBFileExists(szSFileName) != VS_SUCCESS)
                if (inDBCreateFile(szSFileName, sizeof(srCPACSettleBottom)) != VS_SUCCESS)
                    ACTIVITY_LOG("Bottom fopen failed"); //return(VS_ERROR);

            memset(&srCPACSettleBottom, 0x00, sizeof(srCPACSettleBottom));
            srCPACSettleBottom.lnBottomCond = lnMiddleCondition;

            if (inDBWriteRecord(szSFileName, 1, (unsigned char *) &srCPACSettleBottom) < 0)
                ACTIVITY_LOG("Settle Bottom Failed");

            //inRecCnt++;
        }
        // #endif   /* TLFB */  (Made this feature as the part of CPAC Base Application)
        /*Saritha_b1..............End............Reprint Settlement Report */
    }
#endif /* CITI_PHIL */
    if(inPrintError!=0)  //added by KiaSoon: To fix Reprint settlement error
       return VS_ERR;
    else   
       return(VS_SUCCESS);
}


int inCheckAllowed(TRANSACTION_OBJECT *pobTran)
{
	char szSaleAllow[2];
	char szOfflineAllow[2];
	char szAuthAllow[2];
	char szRefundAllow[2];
	char szVoidAllow[2];
	char szAdjustAllow[2];
	char szTipAdjustAllow[2];

	memset (szSaleAllow, 0x00, sizeof(szSaleAllow));
	memset (szOfflineAllow, 0x00, sizeof(szOfflineAllow));
	memset (szAuthAllow, 0x00, sizeof(szAuthAllow));
	memset (szRefundAllow, 0x00, sizeof(szRefundAllow));
	memset (szVoidAllow, 0x00, sizeof(szVoidAllow));
	memset (szAdjustAllow, 0x00, sizeof(szAdjustAllow));
	memset (szTipAdjustAllow, 0x00, sizeof(szTipAdjustAllow));

	get_env("#SALALWD", szSaleAllow, sizeof(szSaleAllow));
	get_env("#OFFALWD", szOfflineAllow, sizeof(szOfflineAllow));
	get_env("#AUTALWD", szAuthAllow, sizeof(szAuthAllow));
	get_env("#REFALWD", szRefundAllow, sizeof(szRefundAllow));
	get_env("#VODALWD", szVoidAllow, sizeof(szVoidAllow));
	get_env("#ADJALWD", szAdjustAllow, sizeof(szAdjustAllow));
	get_env("#TIPALWD", szTipAdjustAllow, sizeof(szTipAdjustAllow));
	
	switch (pobTran->inTransactionCode)
	{
		case SALE:
		case CITI_MANUAL_SALE:
				
			if (((strlen(szSaleAllow))>0)&&(strcmp(szSaleAllow, "1")!=0))
			{
				vdClearStatusMessage ();
				vdSGErrorMessage(0L); /* clear error message */
				vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
				return(VS_ERR);
    		}
			break;

		case SALE_OFFLINE:
			if (((strlen(szOfflineAllow))>0)&&(strcmp(szOfflineAllow, "1")!=0))
			{
				vdClearStatusMessage ();
				vdSGErrorMessage(0L); /* clear error message */
				vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
				return(VS_ERR);
    		}
			break;

		case PRE_AUTH:
		case IMAM_CARDVER:
		case AUTH_ONLY:
			if (((strlen(szAuthAllow))>0)&&(strcmp(szAuthAllow, "1")!=0))
			{
				vdClearStatusMessage ();
				vdSGErrorMessage(0L); /* clear error message */
				vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
				return(VS_ERR);
    		}
			break;

		case REFUND:
			if (((strlen(szRefundAllow))>0)&&(strcmp(szRefundAllow, "1")!=0))
			{
				vdClearStatusMessage ();
				vdSGErrorMessage(0L); /* clear error message */
				vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
				return(VS_ERR);
    		}
			break;

		case VOID:
		case BATCH_REVIEW_VOID:
			if (((strlen(szVoidAllow))>0)&&(strcmp(szVoidAllow, "1")!=0))
			{
				vdClearStatusMessage ();
				vdSGErrorMessage(0L); /* clear error message */
				vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
				return(VS_ERR);
    		}
			break;

		case ADJUST:
		case CPAC_PHIL_ADJUST:
			if (((strlen(szAdjustAllow))>0)&&(strcmp(szAdjustAllow, "1")!=0))
			{
				vdClearStatusMessage ();
				vdSGErrorMessage(0L); /* clear error message */
				vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
				return(VS_ERR);
    		}
			break;

		case TIP_ADJUST:
		case APP_ADJST:
			if (((strlen(szTipAdjustAllow))>0)&&(strcmp(szTipAdjustAllow, "1")!=0))
			{
				vdClearStatusMessage ();
				vdSGErrorMessage(0L); /* clear error message */
				vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
				return(VS_ERR);
    		}
			break;

		default :
			break;
	}

	return (VS_SUCCESS);
}

int inCitiValidateTransaction(TRANSACTION_OBJECT * pobTran)
{
	if(inLoadSIGRec(inGetMerchantNum() - 1) != VS_SUCCESS)
	{
		vdDisplayMessageFromFile(HFT_ERR_MSG, ERROR_MSG);
		return(VS_ERROR);
	}

	switch(pobTran->srTRTRec.TransactionCode)
	{

		case CITI_EPP_SALE:

					if(fGetEppSale() != VS_TRUE)
					{
						vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, ERROR_MSG);
						return(VS_ERR);
					}
					break;

		case CITI_EPP_CASHBACK:

					if(fGetICash() != VS_TRUE)
					{
						vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, ERROR_MSG);
						return(VS_ERR);
					}
					break;

		case CITI_EPP_CASH:

					if(fGetSaleICash() != VS_TRUE)
					{
						vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, ERROR_MSG);
						return(VS_ERR);
					}
					break;
	}

	return(VS_SUCCESS);

}

int enableinvoice(TRANSACTION_OBJECT * pobTran)////ivan
{
char szstatus[2];


	memset (szstatus, 0x00, sizeof(szstatus));

	get_env("#INVALWD", szstatus, sizeof(szstatus));



if (((strlen(szstatus))>0)&&(strcmp(szstatus, "1")==0)){
      	  	      if (inRunFunction(pobTran, GET_INVOICE_NUMBER1) != VS_SUCCESS)
		                {
                                 return(VS_ERR);
		                 }
      	}else{

		 if (inRunFunction(pobTran, CPAC_GET_INV_NUM) != VS_SUCCESS)
		                {
                                 return(VS_ERR);
		                 }
      		}
		return(VS_SUCCESS);
}

int enableinvoiceepp(TRANSACTION_OBJECT * pobTran)////ivan
{
char szstatus[2];


	memset (szstatus, 0x00, sizeof(szstatus));

	get_env("#INVEPPALWD", szstatus, sizeof(szstatus));


if (((strlen(szstatus))>0)&&(strcmp(szstatus, "1")==0)){
	                         if (inRunFunction(pobTran, GET_INVOICE_NUMBER1) != VS_SUCCESS)
		                {
                                 return(VS_ERR);
		                 }
}else{

			 if (inRunFunction(pobTran, CPAC_GET_INV_NUM) != VS_SUCCESS)
		                {
                                 return(VS_ERR);
		                 }
}

	return(VS_SUCCESS);
}

int enableinvoicecash(TRANSACTION_OBJECT * pobTran)////ivan
{
char szstatus[2];


	memset (szstatus, 0x00, sizeof(szstatus));

	get_env("#INVCASHALWD", szstatus, sizeof(szstatus));



if (((strlen(szstatus))>0)&&(strcmp(szstatus, "1")==0)){
      	  	      if (inRunFunction(pobTran, GET_INVOICE_NUMBER1) != VS_SUCCESS)
		                {
                                 return(VS_ERR);
		                 }
      	}else{

		 if (inRunFunction(pobTran, CPAC_GET_INV_NUM) != VS_SUCCESS)
		                {
                                 return(VS_ERR);
		                 }
      		}
		return(VS_SUCCESS);
}

int enableinvoicecabk(TRANSACTION_OBJECT * pobTran)////ivan
{
char szstatus[2];


	memset (szstatus, 0x00, sizeof(szstatus));

	get_env("#INVCABKALWD", szstatus, sizeof(szstatus));



if (((strlen(szstatus))>0)&&(strcmp(szstatus, "1")==0)){
      	  	      if (inRunFunction(pobTran, GET_INVOICE_NUMBER1) != VS_SUCCESS)
		                {
                                 return(VS_ERR);
		                 }
      	}else{

		 if (inRunFunction(pobTran, CPAC_GET_INV_NUM) != VS_SUCCESS)
		                {
                                 return(VS_ERR);
		                 }
      		}
		return(VS_SUCCESS);
}

int enableinvoiceAMEX(TRANSACTION_OBJECT * pobTran)////ivan
{
char szstatus[2];


	memset (szstatus, 0x00, sizeof(szstatus));

	get_env("#INVAMEXALWD", szstatus, sizeof(szstatus));



if (((strlen(szstatus))>0)&&(strcmp(szstatus, "1")==0)){
      	  	      if (inRunFunction(pobTran, GET_INVOICE_NUMBER1) != VS_SUCCESS)
		                {
                                 return(VS_ERR);
		                 }
      	}else{

		 if (inRunFunction(pobTran, CPAC_GET_INV_NUM) != VS_SUCCESS)
		                {
                                 return(VS_ERR);
		                 }
      		}
		return(VS_SUCCESS);
}


int enableinvoiceJCB(TRANSACTION_OBJECT * pobTran)////ivan
{
char szstatus[2];


	memset (szstatus, 0x00, sizeof(szstatus));

	get_env("#INVJCBALWD", szstatus, sizeof(szstatus));



if (((strlen(szstatus))>0)&&(strcmp(szstatus, "1")==0)){
      	  	      if (inRunFunction(pobTran, GET_INVOICE_NUMBER1) != VS_SUCCESS)
		                {
                                 return(VS_ERR);
		                 }
      	}else{

		 if (inRunFunction(pobTran, CPAC_GET_INV_NUM) != VS_SUCCESS)
		                {
                                 return(VS_ERR);
		                 }
      		}
		return(VS_SUCCESS);
}

int enableinvoiceDINERS(TRANSACTION_OBJECT * pobTran)////ivan
{
char szstatus[2];


	memset (szstatus, 0x00, sizeof(szstatus));

	get_env("#INVDINERSALWD", szstatus, sizeof(szstatus));



if (((strlen(szstatus))>0)&&(strcmp(szstatus, "1")==0)){
      	  	      if (inRunFunction(pobTran, GET_INVOICE_NUMBER1) != VS_SUCCESS)
		                {
                                 return(VS_ERR);
		                 }
      	}else{

		 if (inRunFunction(pobTran, CPAC_GET_INV_NUM) != VS_SUCCESS)
		                {
                                 return(VS_ERR);
		                 }
      		}
		return(VS_SUCCESS);
}


int inCITIReprintFileCopy(TRANSACTION_OBJECT *pobTran)
{
	DB_FILE dbReprintFile;

	/* Added for new Reprint Functionality */



        if ( db_open(&dbReprintFile, REPRINT_FILE_NAME, SIZE_BATCH_KEY, (O_TRUNC | O_CREAT | O_RDWR)) < 0 )
        {
            return(VS_ERR);
        }

        if ( inWriteBatchData (&dbReprintFile, &pobTran->srBKey, &pobTran->srBRec, DB_APPEND) != VS_SUCCESS )
        {

            vdSGErrorMessage(BATCH_ERR_MSG);
            return(VS_ERR);
        }

        if ( inCloseBatch(&dbReprintFile) != VS_SUCCESS)
        {

            vdSGErrorMessage(BATCH_ERR_MSG);
        }

        return VS_SUCCESS;
}

 int inSetCITIVoidOnline(TRANSACTION_OBJECT *pobTran)
{

	if (pobTran->srBKey.fVoided)
	{
		if( pobTran->srBKey.fUploaded )
		{
			pobTran->srTRTRec.Offline = VS_FALSE;
		}
		else
		{
			pobTran->srTRTRec.Offline = VS_TRUE;
		}
	}

	if((pobTran->srBRec.inCode == SALE_OFFLINE) && (pobTran->srBKey.fVoided == VS_TRUE))
		pobTran->srTRTRec.Offline = VS_TRUE;
	else if((pobTran->srBRec.lnTipAmount != 0L) && (pobTran->srBKey.fVoided == VS_TRUE))   /* Add by Kelvin_f2 at 4 Feb 2004 */
		pobTran->srTRTRec.Offline = VS_TRUE;
	else
		pobTran->srTRTRec.Offline = VS_FALSE;

	if((pobTran->srBRec.inCode == CITI_EPP_CASH) && (pobTran->srBKey.fVoided == VS_TRUE))
		pobTran->srTRTRec.Offline = VS_FALSE;


	return(VS_SUCCESS);
}

 int inEndEPPComm(TRANSACTION_OBJECT * pobTran)
{
	obCommunication.inEnd(&obCommunication);
  	return(VS_SUCCESS);
}

int inSelectRegularPromo(TRANSACTION_OBJECT * pobTran)
{
	int inRegularPromoValue;
	char szDisplayBuffer[DISP_STR_LEN + 1], szHold[MESSAGE_SIZE + 1];
	char szInterset[MESSAGE_SIZE + 1];
	memset(szInterset, 0x00, sizeof(szInterset));
	memset(szDisplayBuffer, 0x00, sizeof(szDisplayBuffer));
	memset(szHold, 0x00, sizeof(szHold));
	//strcpy(target, "00");
	strcpy(szDisplayBuffer, "SELECT TYPE");
	inRegularPromoValue = obDisp.inDO_ChooseOne(szDisplayBuffer, szHold, (char *)pchGetMsg(SELECT_REGULAR_PROMO_MSG), 2, NULL_PFI);

	if (inRegularPromoValue == VS_ESCAPE)
		return (VS_SUCCESS);

	if (inRegularPromoValue == 1 )
	{
		if(fGetReg() != VS_TRUE)
		{
			vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
		  	return(VS_ERR);
		}
		else
		{
			sprintf(szInterset, "%02d", inGetRegInterset());
			inStoreBatchFieldData(&pobTran->srBRec, CITI_REG_RATE, (unsigned char *)szInterset, 2);
		}
	}
	else
	{
		if (inRegularPromoValue == 2)
		{
			if(fGetPromo() != VS_TRUE)
			{
				vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
		  		return(VS_ERR);
			}
			else
			{
				sprintf(szInterset, "%02d", inGetPromoInterset());
				inStoreBatchFieldData(&pobTran->srBRec, CITI_REG_RATE, (unsigned char *)szInterset, 2);
			}
		}
	}

 	return(VS_SUCCESS);

}

int inGetCITIEPPTenor(TRANSACTION_OBJECT *pobTran)
{
#if 0
    int  inResult;
    unsigned char target[3+1], target1[5+1], target2[3+1];
    memset(target,0x00,sizeof(target));
	memset(target1,0x00,sizeof(target1));
	memset(target2, 0x00, sizeof(target2));
	strcpy((char*)target1,"01");
    if((pobTran->srTRTRec.TransactionCode == CITI_EPP_SALE))
    {

                       vdSetNextLineEntry(); /* force entry on line after prompt */
	                inResult = inEnterWithMessage(ENTER_TENOR_MSG, SCROLL_DISPLAY_FALSE,
                       (char*)target, INPUT_ALNUMS,3, );
	                if(inResult < 0)  	 return(VS_ERR);
			  if(strlen((char*)target) == 1)
			  	{
			  	  memcpy(target2,"00", 2);
			  	}
			  if(strlen((char*)target) == 2)
			  	{
			  	 memcpy(target2, "0", 1);
			  	}
			  if(strlen((char*)target) == 3)
			  	{
			  	  memset(target2,0x00, sizeof(target2));
			  	}
			  strcat((char*)target2, (char*)target);
					strcat((char*)target1,(char*)target2);
	                inStoreBatchFieldData(&pobTran->srBRec, CITI_EPP_TENOR, (unsigned char *)target1, 5);

    }
	#endif
    return(VS_SUCCESS);
}
#if 0
int inValEPPTenor(char *pszBuf)
{

 	int result,inResult,index,inRecNumber;
	char tempBuff[3+1];
TRANSACTION_OBJECT *pobTran;
       index=0;
	inRecNumber=0;
	memcpy(tempBuff,&(pszBuf[0]), strlen(pszBuf));
	result = atoi(tempBuff);

	/*	if (strlen(pszBuf) != 3)
	{
		vdSGErrorMessage(THREE_CH_REQ_MSG);
		return(VS_ERR);
	}*/
 pobTran=pstGet_pobTran();

	//get the total no of records in ETT
	// browse thru the records till u get the record with tenure == result
	//check if enable
	//if yes proceed
	//if no error
	//inLoadTenureHost(result)
	//get the total no of HDT Records
	//check for rec with tenure == result
	//if so load this host
do{
	inResult = inLoadETTRec(index);
	if( inResult == VS_ERR ){
		vdSGErrorMessage(ENTER_VALID_EPP);
               return(VS_ERR);
			   }

             if (result == inGetTenure()){

///////////////////////////////
                               do{
                                  inResult =inLoadHDTRec (inRecNumber);
                              	if( inResult == VS_ERR ){
					// commented out to fix spqalog029
					//vdSGErrorMessage(ENTER_VALID_EPP);
					//inEPPSelectAndLoadHost1 (pobTran,4);
					return(VS_ERR);
			             }



	if(result== inGetMonth()){
                                   //result=inGetMonth();
                                  // pobTran=pstGet_pobTran();
                   if( inGetHost()){
				 inEPPSelectAndLoadHost1 (pobTran,inGetHost());
                      break;
                   	}
			inEPPSelectAndLoadHost1 (pobTran,inRecNumber);
				break;
					}else{
					inRecNumber++;
						}
                               	}while(1);



/////////////////////
		return(VS_SUCCESS);
            }else{
			// commented out to fix spqalog029
			//vdSGErrorMessage(ENTER_VALID_EPP);
                     index++;
             }

}while(1);



	//if(result != 3 && result != 6 && result != 9 && result != 12 && result != 18 && result != 24 && result != 30 && result != 36 )
//	{
	//	vdSGErrorMessage(ENTER_VALID_VALUE);
           //   return(VS_ERR);
//	}


}
#endif
int inGetEPPCashBackAmount(TRANSACTION_OBJECT * pobTran)
{
	int inSelect;
  	char szAmount[AMT_SIZE + 1];
  	char szMessage[MESSAGE_SIZE + 1];

  	memset(szMessage, 0x00, sizeof(szMessage));

  	inLoadSIGRec(inGetMerchantNum() - 1);

  	sprintf(szMessage,"%ld%s%ld%s%ld%s%ld", lnGetCash1(),"~",lnGetCash2(),"~",lnGetCash3(),"~",lnGetCash4());

  	inSelect = obDisp.inDO_ChooseOne(NULL, pchGetMsg(CHOOSE_CASH_BACK_AMOUNT), (char*)szMessage,4, NULL_PFI);

  	if(inSelect == 1)
  	{
  		//strcpy(szAmount, "1000");
  		sprintf(szAmount, "%ld%s", lnGetCash1(), "00");
         	pobTran->srBRec.lnBaseTransactionAmount = atol(szAmount);
  	}
  	else
  		if(inSelect == 2)
  		{
  			//strcpy(szAmount,"5000");
  			sprintf(szAmount, "%ld%s", lnGetCash2(), "00");
         		pobTran->srBRec.lnBaseTransactionAmount = atol(szAmount);
  		}
  		else
  			if(inSelect == 3)
  			{
  				//strcpy(szAmount,"10000");
  				sprintf(szAmount, "%ld%s", lnGetCash3(), "00");
         			pobTran->srBRec.lnBaseTransactionAmount = atol(szAmount);
  			}
  			else
  				if(inSelect == 4)
  				{
  					//strcpy(szAmount,"20000");
  					sprintf(szAmount, "%ld%s", lnGetCash4(), "00");
         				pobTran->srBRec.lnBaseTransactionAmount = atol(szAmount);
  				}
				else
					return(VS_ERROR);

	return(VS_SUCCESS);
}

int inGetEPPCashAmount(TRANSACTION_OBJECT * pobTran)
{
  	int inSelect;
  	char szAmount[AMT_SIZE + 1];
	char szMessage[MESSAGE_SIZE + 1];

  	memset(szMessage, 0x00, sizeof(szMessage));

  	inLoadSIGRec(inGetMerchantNum() - 1);

  	sprintf(szMessage,"%ld%s%ld%s%ld%s%ld", lnGetCash1(),"~",lnGetCash2(),"~",lnGetCash3(),"~",lnGetCash4());

  	inSelect = obDisp.inDO_ChooseOne(NULL, pchGetMsg(CHOOSE_CASH_BACK_AMOUNT), (char*)szMessage,4, NULL_PFI);

  	if(inSelect == 1)
  	{
  		//strcpy(szAmount,"1000");
  		sprintf(szAmount, "%ld%s", lnGetCash1(), "00");
         	pobTran->srBRec.lnTipAmount = atol(szAmount);
  	}
  	else
  		if(inSelect == 2)
  		{
  	  		//strcpy(szAmount,"5000");
  	  		sprintf(szAmount, "%ld%s", lnGetCash2(), "00");
         		pobTran->srBRec.lnTipAmount = atol(szAmount);
  		}
  		else
  			if(inSelect == 3)
  			{
  	  			//strcpy(szAmount,"10000");
  	  			sprintf(szAmount, "%ld%s", lnGetCash3(), "00");
         			pobTran->srBRec.lnTipAmount = atol(szAmount);
  			}
  			else
  				if(inSelect == 4)
  				{
  	  				//strcpy(szAmount,"20000");
  	  				sprintf(szAmount, "%ld%s", lnGetCash4(), "00");
         				pobTran->srBRec.lnTipAmount = atol(szAmount);
  				}
  				else
  					return(VS_ERROR);

	return(VS_SUCCESS);
}


int inGetInvoiceNumber1 (TRANSACTION_OBJECT *pobTran)///ivan
{
    char szInvoiceNumber [INV_NUM_SIZE + 1];
    int  inResult;
    int  inRowLim = inGetRowLim();

	if(pobTran->srTRTRec.TransactionCode == CITI_EPP_SALE)
	{
		delline();
       	printf("EPP SALE");
	}

	//inResult = inEnterWithMessage(INVOICE_MSG, SCROLL_DISPLAY_FALSE, szInvoiceNumber,
		//	INPUT_NUMS, inGetInvNumSize(), inValInvoiceEntry);

//	window(obDisp.inHomeCol, obDisp.inTitleLine, inRowLim, obDisp.inCharsPerColumn);

//////////////////////////////////////////
 while (TRUE)
    {
        if (inResult == VS_SUCCESS)
        {
            vdDisplayMessageFromFile( DUPLICATE_INV_NUM_MSG, STATUS_MSG);
            SVC_WAIT(2000);
        }
        szInvoiceNumber[0] =  '\0';

#if VIP_RMD
        inResult = inEnterWithMessage(INVOICE_MSG, SCROLL_DISPLAY_TRUE, szInvoiceNumber,
                                              INPUT_NUMS, inGetInvNumSize(), inValidateString);
#endif /* VIP_RMD */

		if (getgrid() == 0)
			inResult = inCPACEnterWithMessage (INVOICE_MSG, SCROLL_DISPLAY_TRUE, 3, 6, szInvoiceNumber, INPUT_NUMS, inGetInvNumSize(), inValidateString);
		else
			//inResult = inCPACEnterWithMessage (INVOICE_MSG, SCROLL_DISPLAY_TRUE, 5, 5, szInvoiceNumber, INPUT_NUMS, inGetInvNumSize(), inValidateString);
inResult = inEnterWithMessage(INVOICE_MSG, SCROLL_DISPLAY_FALSE, szInvoiceNumber,
			INPUT_NUMS, inGetInvNumSize(), inValInvoiceEntry);



        window(obDisp.inHomeCol, obDisp.inTitleLine, inRowLim, obDisp.inCharsPerColumn);

        if (gu_clr_state())
            return(VS_ESCAPE);

        if (inResult < 0)
        {
            vdSGErrorMessage (TXN_CANCELLED);
            return (inResult);
        }

        if (atol(szInvoiceNumber) == 0L)
        {
            vdDisplayMessageFromFile( INVALID_INV_NUM_ERR_MSG, STATUS_MSG);
            SVC_WAIT(2000);
            inResult = VS_ERR;
            continue;
        }

        /* Search in the Open Tab Batch for same Invoice Number and Host Type */
        /* Search in the Host Batch for same Invoice Number */
        pobTran->srBKey.lnInvNum = atol(szInvoiceNumber);

//#ifndef CITI_IND
#ifdef BATCH_DEFINED
        inResult = inCheckForDuplicate(pobTran);
#endif // BATCH_DEFINED
//#endif

        if (inResult != VS_SUCCESS)
            break;

    }

vdSetInvNum(pobTran->srBKey.lnInvNum);

    vdSGErrorMessage(0L);

    return(VS_SUCCESS);


////////////////////////////////////////////
	//if (inResult == VS_ESCAPE)
//	{
//		return (VS_ESCAPE);
//	}

//	if (inResult < 0)
	//{
//		return (VS_ERR);
//	}

	//pobTran->srBKey.lnInvNum = atol(szInvoiceNumber);

   // return (VS_SUCCESS);
}


int inCheckHost(TRANSACTION_OBJECT *pobTran)////ivan
{
	char szJCBAllow[2];
	char szDINERSAllow[2];
	char szAMEXAllow[2];

	memset (szJCBAllow, 0x00, sizeof(szJCBAllow));
	memset (szDINERSAllow, 0x00, sizeof(szDINERSAllow));
	memset (szAMEXAllow, 0x00, sizeof(szAMEXAllow));

	get_env("#JCBLWD", szJCBAllow, sizeof(szJCBAllow));
	get_env("#AMEXALWD", szAMEXAllow, sizeof(szAMEXAllow));
	get_env("#DINERSALWD", szDINERSAllow, sizeof(szDINERSAllow));


switch (inGetIssuerNum())
	{
		case AX:
					if (((strlen(szAMEXAllow))>0)&&(strcmp(szAMEXAllow, "1")!=0))
			                      {
				                 vdClearStatusMessage ();
				                    vdSGErrorMessage(0L); /* clear error message */
				                 vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
				                   return(VS_ERR);
						}

			break;

              case JAPAN2:
		case JAPAN1:
		if (((strlen(szJCBAllow))>0)&&(strcmp(szJCBAllow, "1")!=0))
		                            {
                                           		vdClearStatusMessage ();
			                                 	vdSGErrorMessage(0L); /* clear error message */
		                                          vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
				                                  return(VS_ERR);
			                  	}

			break;

		case DINERS:
          if (((strlen(szDINERSAllow))>0)&&(strcmp(szDINERSAllow, "1")!=0))
                       {
                            vdClearStatusMessage ();
                            vdSGErrorMessage(0L); /* clear error message */
                             vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
                             return(VS_ERR);
                         }

			break;


		default :
			break;
	}






    return(VS_SUCCESS);



}

int inBOPSettleAllHosts(TRANSACTION_OBJECT *pobTran)
{
int hostNum;
char chAnswer;
int inVFHostIndex;
int status;///ivan
hostNum=inGetHDTTotRecs();

chAnswer = (char) obDisp.inDO_ChooseOne((char*)pchGetMsg(SETTLE_ALL_HOSTS_MESSAGE)," ", (char *)pchGetMsg(YESNO_MSG5x), 2, NULL_PFI);

if (chAnswer == KEY_YES)
{

for(inVFHostIndex=0;inVFHostIndex < hostNum; inVFHostIndex++)
{
 inLoadHDTRec(inVFHostIndex);
 vdSetHostHandle(inVFHostIndex);
 inRunFunction(pobTran,CPAC_GET_MERCH_ENABLE) ;
 inRunFunction(pobTran,CPAC_SETTLEMENT);
}

}

if(chAnswer == KEY_CANCEL)
	return (VS_ERR);

if (chAnswer == KEY_NO)
{
status=inRunFunction(pobTran,GET_HOST_NUM);
if (status==VS_ESCAPE){
return (VS_ERR);
}else{
inRunFunction(pobTran,CPAC_GET_MERCH_ENABLE) ;
inRunFunction(pobTran,CPAC_SETTLEMENT);
}

}


 return(VS_SUCCESS);
}


int inCITIEditSIGOperation (TRANSACTION_OBJECT *pobTran)
{
    	inConfRecEdit("SIG");
    	if (inLoadSIGRec( 0 ) != VS_SUCCESS)
       	vdDisplayMessageFromFile( HFT_ERR_MSG, ERROR_MSG);

    	return(BRANCH_EXIT);
}


int inCITIEditETTOperation (TRANSACTION_OBJECT *pobTran)
{
    	inConfRecEdit("ETT");
    	if (inLoadETTRec( 0 ) != VS_SUCCESS)
       	vdDisplayMessageFromFile( HFT_ERR_MSG, ERROR_MSG);

    	return(BRANCH_EXIT);
}


int inSelectSaleEpp(TRANSACTION_OBJECT *pobTran)
{
	

#ifndef IMAM_REMOVE

int inSaleEppValue;
	char szDisplayBuffer[DISP_STR_LEN + 1], szHold[MESSAGE_SIZE + 1];
      //int inNumCDTRecords = inGetCDTTotRecs();
	inSelectTran = VS_ERROR;
	/* EPP Sale transaction falg is set to zero, No selection option should be shown */
	if(inLoadSIGRec(0) != VS_SUCCESS)
	{
		vdDisplayErrorMessage(HFT_ERR_MSG);
		return(VS_ERR);
	}

	if(fGetEppSale() != VS_TRUE)
	{
		pmeScrollItem->miSubFuncIndex= SALE;

		printf("SALE");
		vdFlushKeyboardBuffer();

		inSelectTran = SALE;

		return(VS_SUCCESS);

	}
	/* EPP Sale transaction falg is set to zero, No selection option should be shown */

	//Browse thru CDT Records
      //for(int i=0;i<inNumCDTRecords;i++)

	//if( inGetStatus == 1)///ivan
//	{


		//For each CDT Rec check if the host index is EPP Host Index
		//if yes
			//{
		printf("       ");
		memset(szDisplayBuffer, 0x00, sizeof(szDisplayBuffer));
		memset(szHold, 0x00, sizeof(szHold));
		strcpy(szDisplayBuffer, "SELECT TXN");
		inSaleEppValue = obDisp.inDO_ChooseOne(szDisplayBuffer, szHold, (char *)pchGetMsg(SELECT_EPP_SALE_MSG), 2, NULL_PFI);
	//}
//	else{
    //          pmeScrollItem->miSubFuncIndex= SALE;

	//	printf("SALE");
		//vdFlushKeyboardBuffer();

//		inSelectTran = SALE;

	//	return(VS_SUCCESS);
		//}




	if (inSaleEppValue == VS_ESCAPE)
		return (VS_ERR);



	if (inSaleEppValue == 1 )
	{
		pmeScrollItem->miSubFuncIndex= SALE;
             pobTran->inTransactionCode=SALE;///ivan
		vdSGCode(SALE);
		printf("SALE");
		//get_char();
		vdFlushKeyboardBuffer();

		inSelectTran = SALE;
	}

	if (inSaleEppValue == 2)
	{

		pmeScrollItem->miSubFuncIndex= CITI_EPP_SALE;
		//  pmeScrollItem->mlTranMsg=CITI_EPP_SALE_MSG;
		pobTran->inTransactionCode=CITI_EPP_SALE;
		//pobTran->srBRec.inCode = CITI_EPP_SALE;
     		//   pobTran.inTransactionCode = CITI_EPP_SALE;
		vdSGCode(CITI_EPP_SALE);///ivan
    	   	printf("EPP SALE");
	   	//get_char();
          	memset(srRcpt.szTransName, 0x00, sizeof(srRcpt.szTransName));
	   	strcpy(srRcpt.szTransName, "EPP SALE");

          	vdFlushKeyboardBuffer();

          	inSelectTran = EPP;
    	}
#endif
	return(VS_SUCCESS);
}


#if 0
int inEnterCardData1 (TRANSACTION_OBJECT *pobTran)///ivan
{
char	szNull[21 + 1];
int		inResult = VS_ERR, inStatus;
unsigned long	ulTimerCount;
PFI		pinValSwiped, pinValManual;
#ifdef ICC_DEFINED
PFI		pinValICC;
#endif


PFI_TO_PFI_PIN		pinTempFn;
PFI_TO_PSZ_F	pinGetCardBin;
struct	TRACK srCardData;


#ifdef	COUNTER_DEFINED
		COUNTER_OBJECT	obCounter;

		obCounter.inIndex = ALL_RECORDS;
#endif

	//pdebug(("--inEnterCardData--"));

	BT_TRACE ('I', "Account #:");

if (strlen(pobTran->srBRec.szPAN) > 0)
{

	if ((pinGetCardBin = inGetFunctionPointer(GET_CARD_BIN1)) == NULL_PFI)
    {
		/**/pdebug (("inGetFunctionPointer pinValSwiped Error"));/**/
        return(VS_ERR);
    }

	inResult = pinGetCardBin(pobTran, pobTran->srBRec.szPAN, VS_TRUE );
	if (inResult == VS_SUCCESS)
		vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
	return(inResult);

}
	// sets up the Menu
	if ( inRunFunction (pobTran, START_CARD_TRAN) == VS_ERR )
	{
		return (VS_ERR);
	}

	if ((pinValSwiped = inGetFunctionPointer(VALIDATE_SWIPED_CARD1)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValSwiped Error"));
		return(VS_ERR);
	}

	if ((pinValManual = inGetFunctionPointer(VALIDATE_MANUAL_NO1)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValManual Error"));
		return(VS_ERR);
	}
#ifdef ICC_DEFINED
	if ((pinValICC = inGetFunctionPointer(VALIDATE_ICC_CARD)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValManual Error"));
		return(VS_ERR);
	}
	if (Get_Card_State(CUSTOMER_CARD) != CARD_PRESENT)
	    pobTran->inChipStatus = NOT_USING_CHIP;
#endif
	memset(szNull, NULL_CH, (int)sizeof(szNull));

    ulTimerCount = set_itimeout(NO_CLOCK_HANDLE inGetIdleTimeOut(), TM_SECONDS);

	do
	{
		if (CHK_CARD_RDR())
		{
			if ((pinTempFn = inGetFunctionPointer(CARD_READ_OPERATION)) == NULL_PFI)
				return(VS_ERR);
#ifdef COUNTER_DEFINED
			if (pinTempFn(pobTran, pinValSwiped, &inResult) == VS_ERR)
			{
				obCounter.inType = CARD_READ_ERROR;
				inIncCounter(&obCounter, 1);
				return (VS_ERR);
			}
			else
			{
				obCounter.inType = CARD_READ_ATTEMPTED;
				inIncCounter(&obCounter, 1);
			}
#else
			if (pinTempFn(pobTran, pinValSwiped, &inResult) == VS_ERR)
				return (VS_ERR);
#endif	/* COUNTER_DEFINED */
		}
#ifdef ICC_DEFINED
        else if ((Get_Card_State(CUSTOMER_CARD) == CARD_PRESENT) && (pobTran->inChipStatus == NOT_USING_CHIP))
        {
            if ((pinTempFn = inGetFunctionPointer(CARD_READ_OPERATION)) == NULL_PFI)
                return(VS_ERR);
            if (pinTempFn(pobTran, pinValICC, &inResult) == VS_ERR)
                return(VS_ERR);
        	pobTran->srBRec.inChipStatus = pobTran->inChipStatus;
    		vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
        }
#endif
		else if (act_kbd_pending_test(KEY_CANCEL))
		{
			inResult = VS_ESCAPE;
		}
		else if (KBHIT())
		{
			if ((pinTempFn = inGetFunctionPointer(MANUAL_ENTRY_PROCESS)) == NULL_PFI)
				return(VS_ERR);
			inStatus = pinTempFn(pobTran, pinValManual, &inResult);
			if ( inStatus < 0) return (inStatus);
		}

		else if (CHECK_TIMEOUT(ulTimerCount) == 0)
		{
			// KV1 20010118 - Allow terminal to go to sleep
	    	if ( srGDS.fHandHeld && srGDS.fBatteryOperated && get_dock_status () == HANDHELD_UNDOCKED )
			{
				vdTerminalSleep ();
			}
			else
			{
				inResult = VS_ESCAPE;
			}
		}
		/*
		 *		Allow additional custom Card Entry
		 */
		else
		{
			inResult = inRunFunction (pobTran, CHECK_CARD_ENTRY);
		}
	} while (inResult == VS_ERR);

	vdFlushKeyboardBuffer();

	if (inResult >= 0)
	{
		inResult = VS_SUCCESS;
		if ( inRunFunction (pobTran, DISPLAY_CARD_TITLE) == VS_ERR )
			return (VS_ERR);
	}

    vdClrNextLineEntry(); /* turn off */

	//pdebug(("--EXIT inEnterCarddata--"));
	return(inResult);
}




int inEnterCardData2 (TRANSACTION_OBJECT *pobTran)//ivan
{
char	szNull[21 + 1];
int		inResult = VS_ERR, inStatus;
unsigned long	ulTimerCount;
PFI		pinValSwiped, pinValManual;
#ifdef ICC_DEFINED
PFI		pinValICC;
#endif


PFI_TO_PFI_PIN		pinTempFn;
PFI_TO_PSZ_F	pinGetCardBin;
struct	TRACK srCardData;


#ifdef	COUNTER_DEFINED
		COUNTER_OBJECT	obCounter;

		obCounter.inIndex = ALL_RECORDS;
#endif

	//pdebug(("--inEnterCardData--"));

	BT_TRACE ('I', "Account #:");

if (strlen(pobTran->srBRec.szPAN) > 0)
{

	if ((pinGetCardBin = inGetFunctionPointer(GET_CARD_BIN2)) == NULL_PFI)
    {
		/**/pdebug (("inGetFunctionPointer pinValSwiped Error"));/**/
        return(VS_ERR);
    }

	inResult = pinGetCardBin(pobTran, pobTran->srBRec.szPAN, VS_TRUE );
	if (inResult == VS_SUCCESS)
		vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
	return(inResult);

}
	// sets up the Menu
	if ( inRunFunction (pobTran, START_CARD_TRAN) == VS_ERR )
	{
		return (VS_ERR);
	}

	if ((pinValSwiped = inGetFunctionPointer(VALIDATE_SWIPED_CARD2)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValSwiped Error"));
		return(VS_ERR);
	}

	if ((pinValManual = inGetFunctionPointer(VALIDATE_MANUAL_NO2)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValManual Error"));
		return(VS_ERR);
	}
#ifdef ICC_DEFINED
	if ((pinValICC = inGetFunctionPointer(VALIDATE_ICC_CARD)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValManual Error"));
		return(VS_ERR);
	}
	if (Get_Card_State(CUSTOMER_CARD) != CARD_PRESENT)
	    pobTran->inChipStatus = NOT_USING_CHIP;
#endif
	memset(szNull, NULL_CH, (int)sizeof(szNull));

    ulTimerCount = set_itimeout(NO_CLOCK_HANDLE inGetIdleTimeOut(), TM_SECONDS);

	do
	{
		if (CHK_CARD_RDR())
		{
			if ((pinTempFn = inGetFunctionPointer(CARD_READ_OPERATION)) == NULL_PFI)
				return(VS_ERR);
#ifdef COUNTER_DEFINED
			if (pinTempFn(pobTran, pinValSwiped, &inResult) == VS_ERR)
			{
				obCounter.inType = CARD_READ_ERROR;
				inIncCounter(&obCounter, 1);
				return (VS_ERR);
			}
			else
			{
				obCounter.inType = CARD_READ_ATTEMPTED;
				inIncCounter(&obCounter, 1);
			}
#else
			if (pinTempFn(pobTran, pinValSwiped, &inResult) == VS_ERR)
				return (VS_ERR);
#endif	/* COUNTER_DEFINED */
		}
#ifdef ICC_DEFINED
        else if ((Get_Card_State(CUSTOMER_CARD) == CARD_PRESENT) && (pobTran->inChipStatus == NOT_USING_CHIP))
        {
            if ((pinTempFn = inGetFunctionPointer(CARD_READ_OPERATION)) == NULL_PFI)
                return(VS_ERR);
            if (pinTempFn(pobTran, pinValICC, &inResult) == VS_ERR)
                return(VS_ERR);
        	pobTran->srBRec.inChipStatus = pobTran->inChipStatus;
    		vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
        }
#endif
		else if (act_kbd_pending_test(KEY_CANCEL))
		{
			inResult = VS_ESCAPE;
		}
		else if (KBHIT())
		{
			if ((pinTempFn = inGetFunctionPointer(MANUAL_ENTRY_PROCESS)) == NULL_PFI)
				return(VS_ERR);
			inStatus = pinTempFn(pobTran, pinValManual, &inResult);
			if ( inStatus < 0) return (inStatus);
		}

		else if (CHECK_TIMEOUT(ulTimerCount) == 0)
		{
			// KV1 20010118 - Allow terminal to go to sleep
	    	if ( srGDS.fHandHeld && srGDS.fBatteryOperated && get_dock_status () == HANDHELD_UNDOCKED )
			{
				vdTerminalSleep ();
			}
			else
			{
				inResult = VS_ESCAPE;
			}
		}
		/*
		 *		Allow additional custom Card Entry
		 */
		else
		{
			inResult = inRunFunction (pobTran, CHECK_CARD_ENTRY);
		}
	} while (inResult == VS_ERR);

	vdFlushKeyboardBuffer();

	if (inResult >= 0)
	{
		inResult = VS_SUCCESS;
		if ( inRunFunction (pobTran, DISPLAY_CARD_TITLE) == VS_ERR )
			return (VS_ERR);
	}

    vdClrNextLineEntry(); /* turn off */

	//pdebug(("--EXIT inEnterCarddata--"));
	return(inResult);
}



int inEnterCardData3 (TRANSACTION_OBJECT *pobTran)///ivan
{
char	szNull[21 + 1];
int		inResult = VS_ERR, inStatus;
unsigned long	ulTimerCount;
PFI		pinValSwiped, pinValManual;
#ifdef ICC_DEFINED
PFI		pinValICC;
#endif


PFI_TO_PFI_PIN		pinTempFn;
PFI_TO_PSZ_F	pinGetCardBin;
struct	TRACK srCardData;


#ifdef	COUNTER_DEFINED
		COUNTER_OBJECT	obCounter;

		obCounter.inIndex = ALL_RECORDS;
#endif

	//pdebug(("--inEnterCardData--"));

	BT_TRACE ('I', "Account #:");

if (strlen(pobTran->srBRec.szPAN) > 0)
{

	if ((pinGetCardBin = inGetFunctionPointer(GET_CARD_BIN3)) == NULL_PFI)
    {
		/**/pdebug (("inGetFunctionPointer pinValSwiped Error"));/**/
        return(VS_ERR);
    }

	inResult = pinGetCardBin(pobTran, pobTran->srBRec.szPAN, VS_TRUE );
	if (inResult == VS_SUCCESS)
		vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
	return(inResult);

}
	// sets up the Menu
	if ( inRunFunction (pobTran, START_CARD_TRAN) == VS_ERR )
	{
		return (VS_ERR);
	}

	if ((pinValSwiped = inGetFunctionPointer(VALIDATE_SWIPED_CARD3)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValSwiped Error"));
		return(VS_ERR);
	}

	if ((pinValManual = inGetFunctionPointer(VALIDATE_MANUAL_NO3)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValManual Error"));
		return(VS_ERR);
	}
#ifdef ICC_DEFINED
	if ((pinValICC = inGetFunctionPointer(VALIDATE_ICC_CARD)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValManual Error"));
		return(VS_ERR);
	}
	if (Get_Card_State(CUSTOMER_CARD) != CARD_PRESENT)
	    pobTran->inChipStatus = NOT_USING_CHIP;
#endif
	memset(szNull, NULL_CH, (int)sizeof(szNull));

    ulTimerCount = set_itimeout(NO_CLOCK_HANDLE inGetIdleTimeOut(), TM_SECONDS);

	do
	{
		if (CHK_CARD_RDR())
		{
			if ((pinTempFn = inGetFunctionPointer(CARD_READ_OPERATION)) == NULL_PFI)
				return(VS_ERR);
#ifdef COUNTER_DEFINED
			if (pinTempFn(pobTran, pinValSwiped, &inResult) == VS_ERR)
			{
				obCounter.inType = CARD_READ_ERROR;
				inIncCounter(&obCounter, 1);
				return (VS_ERR);
			}
			else
			{
				obCounter.inType = CARD_READ_ATTEMPTED;
				inIncCounter(&obCounter, 1);
			}
#else
			if (pinTempFn(pobTran, pinValSwiped, &inResult) == VS_ERR)
				return (VS_ERR);
#endif	/* COUNTER_DEFINED */
		}
#ifdef ICC_DEFINED
        else if ((Get_Card_State(CUSTOMER_CARD) == CARD_PRESENT) && (pobTran->inChipStatus == NOT_USING_CHIP))
        {
            if ((pinTempFn = inGetFunctionPointer(CARD_READ_OPERATION)) == NULL_PFI)
                return(VS_ERR);
            if (pinTempFn(pobTran, pinValICC, &inResult) == VS_ERR)
                return(VS_ERR);
        	pobTran->srBRec.inChipStatus = pobTran->inChipStatus;
    		vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
        }
#endif
		else if (act_kbd_pending_test(KEY_CANCEL))
		{
			inResult = VS_ESCAPE;
		}
		else if (KBHIT())
		{
			if ((pinTempFn = inGetFunctionPointer(MANUAL_ENTRY_PROCESS)) == NULL_PFI)
				return(VS_ERR);
			inStatus = pinTempFn(pobTran, pinValManual, &inResult);
			if ( inStatus < 0) return (inStatus);
		}

		else if (CHECK_TIMEOUT(ulTimerCount) == 0)
		{
			// KV1 20010118 - Allow terminal to go to sleep
	    	if ( srGDS.fHandHeld && srGDS.fBatteryOperated && get_dock_status () == HANDHELD_UNDOCKED )
			{
				vdTerminalSleep ();
			}
			else
			{
				inResult = VS_ESCAPE;
			}
		}
		/*
		 *		Allow additional custom Card Entry
		 */
		else
		{
			inResult = inRunFunction (pobTran, CHECK_CARD_ENTRY);
		}
	} while (inResult == VS_ERR);

	vdFlushKeyboardBuffer();

	if (inResult >= 0)
	{
		inResult = VS_SUCCESS;
		if ( inRunFunction (pobTran, DISPLAY_CARD_TITLE) == VS_ERR )
			return (VS_ERR);
	}

    vdClrNextLineEntry(); /* turn off */

	//pdebug(("--EXIT inEnterCarddata--"));
	return(inResult);
}



#endif

int inEnterCardData1 (TRANSACTION_OBJECT *pobTran)///ivan
{
char	szNull[21 + 1];
int		inResult = VS_ERR, inStatus;
unsigned long	ulTimerCount;
PFI		pinValSwiped, pinValManual;
#ifdef ICC_DEFINED
PFI		pinValICC;
#endif


PFI_TO_PFI_PIN		pinTempFn;
PFI_TO_PSZ_F	pinGetCardBin;
struct	TRACK srCardData;
	char chEnableEMV = 0; //Renu 18022005 Converted to a global variable

#ifdef	COUNTER_DEFINED
		COUNTER_OBJECT	obCounter;

		obCounter.inIndex = ALL_RECORDS;
#endif

	//pdebug(("--inEnterCardData--"));
	if (ImamActiveMenu->inDataID > 0 && ImamActiveMenu->inDataID <= 10){  //VISAWAVE..Add
		LOG_PRINTFF((0x08L, "CONTACTLESS...."));
		strcpy(pobTran->srBRec.szPAN, "5000000000000001");  //dummy to force host selection, etc before entering amount
	} else {
		LOG_PRINTFF((0x08L, "NORMAL SALE...."));
	}

	BT_TRACE ('I', "Account #:");
	LOG_PRINTFF((0x08L, "GET_CARD_FIELDS1 = inEnterCardData1 =================="));
	get_env("EMV.ALLOWED", (char*)&chEnableEMV, 1); //Getting the value once during cold init
if (strlen(pobTran->srBRec.szPAN) > 0)
{

	if ((pinGetCardBin = inGetFunctionPointer(GET_CARD_BIN1)) == NULL_PFI)
    {
		/**/pdebug (("inGetFunctionPointer pinValSwiped Error"));/**/
        return(VS_ERR);
    }

	inResult = pinGetCardBin(pobTran, pobTran->srBRec.szPAN, VS_TRUE );
	if (inResult == VS_SUCCESS)
		vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
	return(inResult);

}
	// sets up the Menu
	if ( inRunFunction (pobTran, START_CARD_TRAN) == VS_ERR )
	{
		return (VS_ERR);
	}

	if ((pinValSwiped = inGetFunctionPointer(VALIDATE_SWIPED_CARD1)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValSwiped Error"));
		return(VS_ERR);
	}

	if ((pinValManual = inGetFunctionPointer(VALIDATE_MANUAL_NO1)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValManual Error"));
		return(VS_ERR);
	}
#ifdef ICC_DEFINED
	if ((pinValICC = inGetFunctionPointer(VALIDATE_ICC_CARD)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValManual Error"));
		return(VS_ERR);
	}
	if (inVXEMVAPCardPresent() != SUCCESS)
	    pobTran->inChipStatus = NOT_USING_CHIP;
#endif
/************************************ To disable EMV transactions **********************************************/
		LOG_PRINTFF((0x08L, "API : inVXEMVAPCardPresent ==============="));
		if(inVXEMVAPCardPresent() == SUCCESS)
		{
			if(chEnableEMV == '0')
			{
				vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, WARNING_MSG);
				return VS_ERR;
			}
		}
		LOG_PRINTFF((0x08L, "API : inVXEMVAPCardPresent =============== API"));
/************************************ To disable EMV transactions **********************************************/

	memset(szNull, NULL_CH, (int)sizeof(szNull));

    ulTimerCount = set_itimeout(NO_CLOCK_HANDLE inGetIdleTimeOut(), TM_SECONDS);

		do
		{
			if (CHK_CARD_RDR())
			{
			if ((pinTempFn = inGetFunctionPointer(CARD_READ_OPERATION)) == NULL_PFI)
				return(VS_ERR);
#ifdef COUNTER_DEFINED
			if (pinTempFn(pobTran, pinValSwiped, &inResult) == VS_ERR)
			{
				obCounter.inType = CARD_READ_ERROR;
				inIncCounter(&obCounter, 1);
				return (VS_ERR);
			}
			else
			{
				obCounter.inType = CARD_READ_ATTEMPTED;
				inIncCounter(&obCounter, 1);
			}
#else
			if (pinTempFn(pobTran, pinValSwiped, &inResult) == VS_ERR)
				return (VS_ERR);
#endif	/* COUNTER_DEFINED */

			#ifdef VXEMVAPP
			//Check if the swiped card is a chip card
			//To skip Service code checking

			if (fGetChkServiceCode())
			{


				if((pobTran->szServiceCode[0] == '2') || (pobTran->szServiceCode[0] == '6'))
				{

					if(inEMVGetICCReadFailure() == VS_FALSE)
					{

						vdDisplayMessageFromFile(EMV_USE_CHIP_READER, ERROR_MSG);
						vdSGErrorMessage(0L);
						return(VS_ERR);
					}
				}
			}
			#endif /* VXEMVAPP */
		}
#ifdef ICC_DEFINED
        else if ((inVXEMVAPCardPresent() == SUCCESS) && (pobTran->inChipStatus == NOT_USING_CHIP))
        {
/************************************ To disable EMV transactions **********************************************/
	            if(chEnableEMV != '0')
	            {

		            if ((pinTempFn = inGetFunctionPointer(CARD_READ_OPERATION)) == NULL_PFI)
		                return(VS_ERR);
					LOG_PRINTFF((0x08L, "Calling..CARD_READ_OPERATION with VALIDATE_ICC_CARD as par"));
		            if (pinTempFn(pobTran, pinValICC, &inResult) == VS_ERR)
		                return(VS_ERR);
					LOG_PRINTFF((0x08L, "Calling..CARD_READ_OPERATION with VALIDATE_ICC_CARD as par OK"));
		        	pobTran->srBRec.inChipStatus = pobTran->inChipStatus;
		    		vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
	            	}
			else
			{
				vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, WARNING_MSG);
				return VS_ERR;
			}
	        }
/************************************ To disable EMV transactions **********************************************/
#endif
		else if (act_kbd_pending_test(KEY_CANCEL))
		{
			inResult = VS_ESCAPE;
		}
		else if (KBHIT())
		{
			if ((pinTempFn = inGetFunctionPointer(MANUAL_ENTRY_PROCESS)) == NULL_PFI)
				return(VS_ERR);
			inStatus = pinTempFn(pobTran, pinValManual, &inResult);
			if ( inStatus < 0) return (inStatus);
		}

		else if (CHECK_TIMEOUT(ulTimerCount) == 0)
		{
			// KV1 20010118 - Allow terminal to go to sleep
	    	if ( srGDS.fHandHeld && srGDS.fBatteryOperated && get_dock_status () == HANDHELD_UNDOCKED )
			{
				vdTerminalSleep (); 
			}
			else
			{
				inResult = VS_ESCAPE;
			}
		}
		/*
		 *		Allow additional custom Card Entry
		 */
		else
		{
			inResult = inRunFunction (pobTran, CHECK_CARD_ENTRY);
		}
	} while (inResult == VS_ERR);

	vdFlushKeyboardBuffer();

	if (inResult >= 0)
	{
		inResult = VS_SUCCESS;
		LOG_PRINTFF((0x08L, "Calling DISPLAY_CARD_TITLE====="));
		if ( inRunFunction (pobTran, DISPLAY_CARD_TITLE) == VS_ERR )
			return (VS_ERR);
		LOG_PRINTFF((0x08L, "Calling DISPLAY_CARD_TITLE====OK"));
	}

    vdClrNextLineEntry(); /* turn off */

	//pdebug(("--EXIT inEnterCarddata--"));
	LOG_PRINTFF((0x08L, "GET_CARD_FIELDS1 = inEnterCardData1 ================== GET_CARD_FIELDS1"));
	return(inResult);
}


int inEnterCardData2 (TRANSACTION_OBJECT *pobTran)
{



int		inResult = VS_ERR;//, inStatus;

#ifndef IMAM_REMOVE
char	szNull[21 + 1];
int inStatus;
unsigned long	ulTimerCount;
PFI		pinValSwiped, pinValManual;
#ifdef ICC_DEFINED
PFI		pinValICC;
#endif


PFI_TO_PFI_PIN		pinTempFn;
PFI_TO_PSZ_F	pinGetCardBin;
struct	TRACK srCardData;
	char chEnableEMV = 0; //Renu 18022005 Converted to a global variable

#ifdef	COUNTER_DEFINED
		COUNTER_OBJECT	obCounter;

		obCounter.inIndex = ALL_RECORDS;
#endif

	//pdebug(("--inEnterCardData--"));

	BT_TRACE ('I', "Account #:");

	get_env("EMV.ALLOWED", (char*)&chEnableEMV, 1); //Getting the value once during cold init
if (strlen(pobTran->srBRec.szPAN) > 0)
{

	if ((pinGetCardBin = inGetFunctionPointer(GET_CARD_BIN2)) == NULL_PFI)
    {
		/**/pdebug (("inGetFunctionPointer pinValSwiped Error"));/**/
        return(VS_ERR);
    }

	inResult = pinGetCardBin(pobTran, pobTran->srBRec.szPAN, VS_TRUE );
	if (inResult == VS_SUCCESS)
		vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
	return(inResult);

}
	// sets up the Menu
	if ( inRunFunction (pobTran, START_CARD_TRAN) == VS_ERR )
	{
		return (VS_ERR);
	}

	if ((pinValSwiped = inGetFunctionPointer(VALIDATE_SWIPED_CARD2)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValSwiped Error"));
		return(VS_ERR);
	}

	if ((pinValManual = inGetFunctionPointer(VALIDATE_MANUAL_NO2)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValManual Error"));
		return(VS_ERR);
	}
#ifdef ICC_DEFINED
	if ((pinValICC = inGetFunctionPointer(VALIDATE_ICC_CARD)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValManual Error"));
		return(VS_ERR);
	}
	if (inVXEMVAPCardPresent() != SUCCESS)
	    pobTran->inChipStatus = NOT_USING_CHIP;
#endif

/************************************ To disable EMV transactions **********************************************/
		if(inVXEMVAPCardPresent() == SUCCESS)
		{
			if(chEnableEMV == '0')
			{
				vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, WARNING_MSG);
				return VS_ERR;
			}
		}
/************************************ To disable EMV transactions **********************************************/

	memset(szNull, NULL_CH, (int)sizeof(szNull));

    ulTimerCount = set_itimeout(NO_CLOCK_HANDLE inGetIdleTimeOut(), TM_SECONDS);

	do
	{
		if (CHK_CARD_RDR())
		{
			if ((pinTempFn = inGetFunctionPointer(CARD_READ_OPERATION)) == NULL_PFI)
				return(VS_ERR);
#ifdef COUNTER_DEFINED
			if (pinTempFn(pobTran, pinValSwiped, &inResult) == VS_ERR)
			{
				obCounter.inType = CARD_READ_ERROR;
				inIncCounter(&obCounter, 1);
				return (VS_ERR);
			}
			else
			{
				obCounter.inType = CARD_READ_ATTEMPTED;
				inIncCounter(&obCounter, 1);
			}
#else
			if (pinTempFn(pobTran, pinValSwiped, &inResult) == VS_ERR)
				return (VS_ERR);
#endif	/* COUNTER_DEFINED */

			#ifdef VXEMVAPP
			//Check if the swiped card is a chip card
			//To skip Service code checking

			if (fGetChkServiceCode())
			{

				if((pobTran->szServiceCode[0] == '2') || (pobTran->szServiceCode[0] == '6'))
				{

					if(inEMVGetICCReadFailure() == VS_FALSE)
					{

						vdDisplayMessageFromFile(EMV_USE_CHIP_READER, ERROR_MSG);
						vdSGErrorMessage(0L);
						return(VS_ERR);
					}
				}
			}
			#endif /* VXEMVAPP */
		}
#ifdef ICC_DEFINED
        else if ((inVXEMVAPCardPresent() == SUCCESS) && (pobTran->inChipStatus == NOT_USING_CHIP))
        {
/************************************ To disable EMV transactions **********************************************/
	            if(chEnableEMV != '0')
	            {

		            if ((pinTempFn = inGetFunctionPointer(CARD_READ_OPERATION)) == NULL_PFI)
		                return(VS_ERR);
		            if (pinTempFn(pobTran, pinValICC, &inResult) == VS_ERR)
		                return(VS_ERR);
		        	pobTran->srBRec.inChipStatus = pobTran->inChipStatus;
		    		vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
	            	}
			else
			{
				vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, WARNING_MSG);
				return VS_ERR;
			}
	        }
/************************************ To disable EMV transactions **********************************************/
#endif
		else if (act_kbd_pending_test(KEY_CANCEL))
		{
			inResult = VS_ESCAPE;
		}
		else if (KBHIT())
		{
			if ((pinTempFn = inGetFunctionPointer(MANUAL_ENTRY_PROCESS)) == NULL_PFI)
				return(VS_ERR);
			inStatus = pinTempFn(pobTran, pinValManual, &inResult);
			if ( inStatus < 0) return (inStatus);
		}

		else if (CHECK_TIMEOUT(ulTimerCount) == 0)
		{
			// KV1 20010118 - Allow terminal to go to sleep
	    	if ( srGDS.fHandHeld && srGDS.fBatteryOperated && get_dock_status () == HANDHELD_UNDOCKED )
			{
				vdTerminalSleep ();
			}
			else
			{
				inResult = VS_ESCAPE;
			}
		}
		/*
		 *		Allow additional custom Card Entry
		 */
		else
		{
			inResult = inRunFunction (pobTran, CHECK_CARD_ENTRY);
		}
	} while (inResult == VS_ERR);

	vdFlushKeyboardBuffer();

	if (inResult >= 0)
	{
		inResult = VS_SUCCESS;
		if ( inRunFunction (pobTran, DISPLAY_CARD_TITLE) == VS_ERR )
			return (VS_ERR);
	}

    vdClrNextLineEntry(); /* turn off */
#endif //IMAM_REMOVE
	//pdebug(("--EXIT inEnterCarddata--"));
	return(inResult);
}


int inEnterCardData3 (TRANSACTION_OBJECT *pobTran)///ivan
{

int		inResult = VS_ERR;

#ifndef IMAM_REMOVE
char	szNull[21 + 1];
int		inResult = VS_ERR, inStatus;

unsigned long	ulTimerCount;
PFI		pinValSwiped, pinValManual;
#ifdef ICC_DEFINED
PFI		pinValICC;
#endif


PFI_TO_PFI_PIN		pinTempFn;
PFI_TO_PSZ_F	pinGetCardBin;
struct	TRACK srCardData;
	char chEnableEMV = 0; //Renu 18022005 Converted to a global variable

#ifdef	COUNTER_DEFINED
		COUNTER_OBJECT	obCounter;

		obCounter.inIndex = ALL_RECORDS;
#endif

	//pdebug(("--inEnterCardData--"));

	BT_TRACE ('I', "Account #:");

	get_env("EMV.ALLOWED", (char*)&chEnableEMV, 1); //Getting the value once during cold init
if (strlen(pobTran->srBRec.szPAN) > 0)
{

	if ((pinGetCardBin = inGetFunctionPointer(GET_CARD_BIN3)) == NULL_PFI)
    {
		/**/pdebug (("inGetFunctionPointer pinValSwiped Error"));/**/
        return(VS_ERR);
    }

	inResult = pinGetCardBin(pobTran, pobTran->srBRec.szPAN, VS_TRUE );
	if (inResult == VS_SUCCESS)
		vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
	return(inResult);

}
	// sets up the Menu
	if ( inRunFunction (pobTran, START_CARD_TRAN) == VS_ERR )
	{
		return (VS_ERR);
	}

	if ((pinValSwiped = inGetFunctionPointer(VALIDATE_SWIPED_CARD3)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValSwiped Error"));
		return(VS_ERR);
	}

	if ((pinValManual = inGetFunctionPointer(VALIDATE_MANUAL_NO3)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValManual Error"));
		return(VS_ERR);
	}
#ifdef ICC_DEFINED
	if ((pinValICC = inGetFunctionPointer(VALIDATE_ICC_CARD)) == NULL_PFI)
	{
		//pdebug (("inGetFunctionPointer pinValManual Error"));
		return(VS_ERR);
	}
	if (inVXEMVAPCardPresent() != SUCCESS)
	    pobTran->inChipStatus = NOT_USING_CHIP;
#endif

/************************************ To disable EMV transactions **********************************************/
		if(inVXEMVAPCardPresent() == SUCCESS)
		{
			if(chEnableEMV == '0')
			{
				vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, WARNING_MSG);
				return VS_ERR;
			}
		}
/************************************ To disable EMV transactions **********************************************/

	memset(szNull, NULL_CH, (int)sizeof(szNull));

    ulTimerCount = set_itimeout(NO_CLOCK_HANDLE inGetIdleTimeOut(), TM_SECONDS);

	do
	{
		if (CHK_CARD_RDR())
		{
			if ((pinTempFn = inGetFunctionPointer(CARD_READ_OPERATION)) == NULL_PFI)
				return(VS_ERR);
#ifdef COUNTER_DEFINED
			if (pinTempFn(pobTran, pinValSwiped, &inResult) == VS_ERR)
			{
				obCounter.inType = CARD_READ_ERROR;
				inIncCounter(&obCounter, 1);
				return (VS_ERR);
			}
			else
			{
				obCounter.inType = CARD_READ_ATTEMPTED;
				inIncCounter(&obCounter, 1);
			}
#else
			if (pinTempFn(pobTran, pinValSwiped, &inResult) == VS_ERR)
				return (VS_ERR);
#endif	/* COUNTER_DEFINED */

			#ifdef VXEMVAPP
			//Check if the swiped card is a chip card
			//To skip Service code checking

			if (fGetChkServiceCode())
			{

				if((pobTran->szServiceCode[0] == '2') || (pobTran->szServiceCode[0] == '6'))
				{

					if(inEMVGetICCReadFailure() == VS_FALSE)
					{

						vdDisplayMessageFromFile(EMV_USE_CHIP_READER, ERROR_MSG);
						vdSGErrorMessage(0L);
						return(VS_ERR);
					}
				}
			}
			#endif /* VXEMVAPP */
		}
#ifdef ICC_DEFINED
        else if ((inVXEMVAPCardPresent() == SUCCESS) && (pobTran->inChipStatus == NOT_USING_CHIP))
        {
/************************************ To disable EMV transactions **********************************************/
	            if(chEnableEMV != '0')
	            {

		            if ((pinTempFn = inGetFunctionPointer(CARD_READ_OPERATION)) == NULL_PFI)
		                return(VS_ERR);
		            if (pinTempFn(pobTran, pinValICC, &inResult) == VS_ERR)
		                return(VS_ERR);
		        	pobTran->srBRec.inChipStatus = pobTran->inChipStatus;
		    		vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
	            	}
			else
			{
				vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, WARNING_MSG);
				return VS_ERR;
			}
	        }
/************************************ To disable EMV transactions **********************************************/
#endif
		else if (act_kbd_pending_test(KEY_CANCEL))
		{
			inResult = VS_ESCAPE;
		}
		else if (KBHIT())
		{
			if ((pinTempFn = inGetFunctionPointer(MANUAL_ENTRY_PROCESS)) == NULL_PFI)
				return(VS_ERR);
			inStatus = pinTempFn(pobTran, pinValManual, &inResult);
			if ( inStatus < 0) return (inStatus);
		}

		else if (CHECK_TIMEOUT(ulTimerCount) == 0)
		{
			// KV1 20010118 - Allow terminal to go to sleep
	    	if ( srGDS.fHandHeld && srGDS.fBatteryOperated && get_dock_status () == HANDHELD_UNDOCKED )
			{
				vdTerminalSleep ();
			}
			else
			{
				inResult = VS_ESCAPE;
			}
		}
		/*
		 *		Allow additional custom Card Entry
		 */
		else
		{
			inResult = inRunFunction (pobTran, CHECK_CARD_ENTRY);
		}
	} while (inResult == VS_ERR);

	vdFlushKeyboardBuffer();

	if (inResult >= 0)
	{
		inResult = VS_SUCCESS;
		if ( inRunFunction (pobTran, DISPLAY_CARD_TITLE) == VS_ERR )
			return (VS_ERR);
	}

    vdClrNextLineEntry(); /* turn off */
#endif //IMAM_REMOVE
	//pdebug(("--EXIT inEnterCarddata--"));
	return(inResult);
}


int inGetCardBin1 (TRANSACTION_OBJECT *pobTran,char *pchCardNum,unsigned fManual)///ivan
{
int		inCDTIndex, inCardLen;
PFI_TO_PSZ		pinLoadGetCDTIndex;

	//pdebug(("--inGetCardBin--"));

    if ((pinLoadGetCDTIndex = inGetFunctionPointer(LOAD_GET_CDT1)) == NULL_PFI)
    {
		//pdebug (("inGetFunctionPointer pinLoadGetCDTIndex Error"));
        return(VS_ERR);
    }

   /* Remove Spaces from account number */
   	purge_char(pchCardNum, ' ');

    inCDTIndex = pinLoadGetCDTIndex(pobTran, pchCardNum);

	if (inCDTIndex < 0)
	{
        if (inCDTIndex !=VS_ESCAPE)
        {
           //pdebug (("inGetCardBin-1"));
		   vdSGErrorMessage(NOT_SUPPORTED_ERR_MSG21);
		}
		return(inCDTIndex);
	}

	/* Check for proper card length */
	inCardLen = strlen(pchCardNum);

	if ((inCardLen < inGetMinPANDigit()) ||
		(inCardLen > inGetMaxPANDigit()))
	{
		vdSGErrorMessage(INV_CARD_LEN_ERR_MSG21);
		return(VS_ERR);
	}
	
	//if (fGetChkLuhn() == VS_TRUE)	/* Check Luhn */
	if (fGetChkLuhn() == VS_TRUE && (ImamActiveMenu->inDataID==0 || ImamActiveMenu->inDataID>10))  //VISAWAVE NO CHECKING
	{
		if (chk_luhn(pchCardNum) != 1)
		{
			LOG_PRINTFF((0x08L, "CHECK LUHN FAIL"));
			vdSGErrorMessage(BAD_LUHN_MSG21);
			return (VS_ERR);
		}
		LOG_PRINTFF((0x08L, "CHECK LUHN OK"));
	}

    if (fGetDebitFlag()!= DEBIT && inGetType() == DEBIT_CARD )
    {
        //pdebug (("inGetCardBin-2"));
		vdSGErrorMessage(NOT_SUPPORTED_ERR_MSG21);
		return(VS_ERR);
    }

	return(VS_SUCCESS);
}



int inGetCardBin2 (TRANSACTION_OBJECT *pobTran,char *pchCardNum,unsigned fManual)///ivan
{
#ifndef IMAM_REMOVE
int		inCDTIndex, inCardLen;
PFI_TO_PSZ		pinLoadGetCDTIndex;

	//pdebug(("--inGetCardBin--"));

    if ((pinLoadGetCDTIndex = inGetFunctionPointer(LOAD_GET_CDT2)) == NULL_PFI)
    {
		//pdebug (("inGetFunctionPointer pinLoadGetCDTIndex Error"));
        return(VS_ERR);
    }

   /* Remove Spaces from account number */
   	purge_char(pchCardNum, ' ');

    inCDTIndex = pinLoadGetCDTIndex(pobTran, pchCardNum);

	if (inCDTIndex < 0)
	{
        if (inCDTIndex !=VS_ESCAPE)
        {
           //pdebug (("inGetCardBin-1"));
		   vdSGErrorMessage(NOT_SUPPORTED_ERR_MSG21);
		}
		return(inCDTIndex);
	}

	/* Check for proper card length */
	inCardLen = strlen(pchCardNum);

	if ((inCardLen < inGetMinPANDigit()) ||
		(inCardLen > inGetMaxPANDigit()))
	{
		vdSGErrorMessage(INV_CARD_LEN_ERR_MSG21);
		return(VS_ERR);
	}

	if (fGetChkLuhn() == VS_TRUE)	/* Check Luhn */
	{
		if (chk_luhn(pchCardNum) != 1)
		{
			vdSGErrorMessage(BAD_LUHN_MSG21);
			return (VS_ERR);
		}
	}


    if (fGetDebitFlag()!= DEBIT && inGetType() == DEBIT_CARD )
    {
        //pdebug (("inGetCardBin-2"));
		vdSGErrorMessage(NOT_SUPPORTED_ERR_MSG21);
		return(VS_ERR);
    }
#endif //IMAM_REMOVE
	return(VS_SUCCESS);
}

int inGetCardBin3 (TRANSACTION_OBJECT *pobTran,char *pchCardNum,unsigned fManual)///ivan
{
#ifndef IMAM_REMOVE
int		inCDTIndex, inCardLen;
PFI_TO_PSZ		pinLoadGetCDTIndex;

	//pdebug(("--inGetCardBin--"));

    if ((pinLoadGetCDTIndex = inGetFunctionPointer(LOAD_GET_CDT3)) == NULL_PFI)
    {
		//pdebug (("inGetFunctionPointer pinLoadGetCDTIndex Error"));
        return(VS_ERR);
    }

   /* Remove Spaces from account number */
   	purge_char(pchCardNum, ' ');

    inCDTIndex = pinLoadGetCDTIndex(pobTran, pchCardNum);

	if (inCDTIndex < 0)
	{
        if (inCDTIndex !=VS_ESCAPE)
        {
           //pdebug (("inGetCardBin-1"));
		   vdSGErrorMessage(NOT_SUPPORTED_ERR_MSG21);
		}
		return(inCDTIndex);
	}

	/* Check for proper card length */
	inCardLen = strlen(pchCardNum);

	if ((inCardLen < inGetMinPANDigit()) ||
		(inCardLen > inGetMaxPANDigit()))
	{
		vdSGErrorMessage(INV_CARD_LEN_ERR_MSG21);
		return(VS_ERR);
	}

	if (fGetChkLuhn() == VS_TRUE)	/* Check Luhn */
	{
		if (chk_luhn(pchCardNum) != 1)
		{
			vdSGErrorMessage(BAD_LUHN_MSG21);
			return (VS_ERR);
		}
	}


    if (fGetDebitFlag()!= DEBIT && inGetType() == DEBIT_CARD )
    {
        //pdebug (("inGetCardBin-2"));
		vdSGErrorMessage(NOT_SUPPORTED_ERR_MSG21);
		return(VS_ERR);
    }
#endif //IMAM_REMOVE
	return(VS_SUCCESS);
}


int inCPACValidateSwipedCard1 (TRANSACTION_OBJECT *pobTran)
{
int		inResult,
		inStatus = VS_SUCCESS;
		//inTrackNumber; 1.4


VS_BOOL fTrack2Valid = VS_FALSE;
VS_BOOL fTrack1Valid = VS_FALSE;
char	chCardBuffer[CARD_SIZE + 1];
struct	TRACK srCardData; //, srCPACCardData; 1.4 _LINT
/* PFI		pinGetCardBin; 1.4 */
PFI_TO_PSZ_F	pinGetCardBin; // mofified in 1.4
// to be added in 1.4 PFI_PSZ     	pinCheckExpDate;
char	szCardLabel[CLABEL_SIZE + 1];  //CPAC_AMEX
char    szTrackPriority[TRACKS_ALLOWED+1]; //1.4
char    szTracksReq[TRACKS_ALLOWED+1];     //1.4
//PRINTER_OBJECT *pobPrinter;


    if ((pinGetCardBin = inGetFunctionPointer(GET_CARD_BIN1)) == NULL_PFI)
    {
		/**/pdebug (("inGetFunctionPointer pinValSwiped Error"));/**/
        return(VS_ERR);
    }

	/**/pdebug(("--inValidateSwipedCard--"));/**/
	pobTran->srBRec.fManual = VS_FALSE;

/** changed 03/30/99 **/

    inResult = read(hCardReader, chCardBuffer, CARD_SIZE);
    #ifdef SHELL_FLEET

	    for (i=0;i<CARD_SIZE;i++)
		szKbdBuf[i] = chCardBuffer[i]; 	/*	Saritha_b1 added on 2nd July for Shell Application.This value is used in Shellsrc.C file */
    #endif

	if(inResult <= 6)
	{
		/* -- ba1: increment the card read error counter -- */

		INCREMENT_CARD_ERROR;
		vdSGErrorMessage(CARDREAD_ERR_MSG);
		return(VS_ERR);
	}

	/* inTrackNumber = inGetTCTTrackNumber();  //1.4
	if (!(inTrackNumber && BOTH_TRACKS_MASK))
	{
		INCREMENT_CARD_ERROR;
 		vdSGErrorMessage(INVALID_TCT_TRACK_MSG21);
 		return(VS_ERR);
	} */ //1.4
	strcpy ( szTrackPriority , szGetTracks());

	if (strpbrk(szTrackPriority,"123")==NULL_CH) {
		INCREMENT_CARD_ERROR;
 		vdSGErrorMessage(INVALID_TCT_TRACK_MSG21);
 		return(VS_ERR);
	}

	/* Parse card to get acct number to determine if debit
	   handle card parse error */

    inResult = card_parse(chCardBuffer, &srCardData, szTrackPriority);
	if(inResult < 0 )
	{
		INCREMENT_CARD_ERROR;
		vdGetCardParseError ((long)inResult);
 		return(VS_ERR);
	}

 /*   inResult = card_parse(chCardBuffer, &srCPACCardData, "2");
	if(inResult < 0 )
	{
		INCREMENT_CARD_ERROR;
		vdGetCardParseError ((long)inResult);
 		return(VS_ERR);
	}*/ //1.4

/*	strcpy(srCardData.acct, srCPACCardData.acct);  */ // 1.4 card swipe fix

   /* inValInteracDebit (pobTran, &srCardData); */ // commented in core also 1.4

	/**/pdebug(("card parse ret %d", inResult));/**/
    if ((inResult = pinGetCardBin (pobTran, srCardData.acct, VS_FALSE)) <= VS_ERR)
    {
		return(inResult);
	}

 #ifdef VXEMVAPP
	strcpy(pobTran->szServiceCode, srCardData.type);
#else
    /* Gw fix from 2.5 - save service code for FPS no auth requires txn.*/
	strcpy(pobTran->srBRec.szAuthCode, srCardData.type);
#endif /* VXEMVAPP */
	strcpy(pobTran->srBRec.szPAN, srCardData.acct);

    /* Form the Last 5 Acct # to Key Structure */
    //strlcpy(pobTran->srBKey.SAcctNum,&pobTran->srBRec.szPAN[strlen(pobTran->srBRec.szPAN) - 5],(FIVE_DIGIT_ACCT + 1));
    pobTran->srBKey.lnLast4 = str2long (&pobTran->srBRec.szPAN[strlen(pobTran->srBRec.szPAN) - LAST4_DIGIT_ACCT]);

	vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
    if((pobTran->srBRec.inTranCardType == DEBIT_CARD ||
        pobTran->srBRec.inTranCardType == EBT_CARD)
 #ifdef PINPAD_DEFINED
            &&
        ((!gfPPadPresent) || (inGetPINPadType() == NO_PINPAD))
#endif /* PINPAD_DEFINED */
        )
    {
        //vdDisplayMessageFromFile( TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
    	vdSGErrorMessage(PINPAD_ERR_MSG21);
		INCREMENT_PINPAD_ERROR;
        return(VS_ERR);
    }
	//strcpy (szTracksReq,szGetTracks());
	strcpy (szTracksReq,szGetTracksRequired());  //spqalog097

	if ( strpbrk(szTrackPriority,"1")!= NULL_CH )
	{
       inResult = card_parse(chCardBuffer, &srCardData, "1");

		if(inResult == 1)
		{
			inStatus = inCheckTrackOneData(&srCardData, inResult);
			if (inStatus == VS_ERR)
        	{
		 		if ((strpbrk(szTrackPriority,"23")==NULL_CH) || (strpbrk(szTracksReq,"1")!=NULL_CH))
    				return VS_ERR;		  /* Error Message is being set in inChecTranOneData */
	        }
    	    else
        	{
            	fTrack1Valid = VS_TRUE;
               	memcpy(pobTran->srBRec.stT1Data, (char *) srCardData.track, TRACK1_SIZE);/* Store Track 1  */
 				pobTran->srBRec.fT1Data = VS_TRUE; //joey /*Added since Track1 was not getting stored in the batch... sowmya*/
 				strcpy(pobTran->srBRec.szCHolder, srCardData.name);
//CPAC_AMEX
				pobTran->srBRec.fCHolder = VS_TRUE;
				strcpy (szCardLabel, szGetCardLabel());
				//vdGetCardLabel(szCardLabel);	/* AMEX expiry date checking not required JD */
				if ((strncmp(szCardLabel, "AMEX", 4) == 0))///ivan
				{
    			if ( fGetExpDtReqd() )
    			{
    				inResult = inValidateExpDate(srCardData.exp);
      				if (inResult != VS_SUCCESS)
	    					return(inResult);
	    			}
	    	    }
    			strcpy(pobTran->srBRec.szExpDate, srCardData.exp);
       		}
       	}
       	else
       		if ((strpbrk(szTrackPriority,"23")==NULL_CH) || (strpbrk(szTracksReq,"1")!=NULL_CH))
       		{
       			vdGetCardParseError((long)inResult);
       			return VS_ERR;
       		}
	}

	if ( fTrack1Valid == VS_FALSE )
    	{
	    strcpy(pobTran->srBRec.szCHolder, "");
	    pobTran->srBRec.fCHolder = VS_FALSE;
	}

	if (strpbrk(szTrackPriority,"2")!=NULL_CH )
	{
		inResult = card_parse(chCardBuffer, &srCardData, "2");
		/**/pdebug(("card parse ret %d", inResult));/**/
		inStatus = inCheckTrackTwoData(&srCardData, inResult);
		if ( inStatus == VS_ERR )
		{
		    if ( fTrack1Valid == VS_FALSE )
    		   	return VS_ERR;	  /* Error Message is being set in inChecTranOneData */

		    /*Praveen_ 20/01/2003_ Fix for track2 Bug*/
           	   if (strpbrk(szTracksReq,"2") != NULL_CH)
                	return VS_ERR;

		}
		else
        {
            fTrack2Valid = VS_TRUE;
    		/**/pdebug(("Track2Valid"));/**/
           	memcpy(pobTran->srBRec.stT2Data, (char *) srCardData.track, TRACK2_SIZE);/* Store Track 2  */
		    pobTran->srBRec.fT2Data = VS_TRUE; //joey /*Added since Track2 was not getting stored in the batch... sowmya*/
		    if ( fTrack1Valid == VS_FALSE )
 					strcpy(pobTran->srBRec.szCHolder, "");
//CPAC_AMEX
			strcpy (szCardLabel, szGetCardLabel());
	//		vdGetCardLabel(szCardLabel);	/* AMEX expiry date checking not required JD */
			if ((strncmp(szCardLabel, "AMEX", 4) != 0))
			{
    		if ( fGetExpDtReqd() )
    		{
				inResult = inValidateExpDate(srCardData.exp);
    			if(inResult != VS_SUCCESS)
	    			return(inResult);
	    	}
			}
/* LENIN  Check above lines */
    		strcpy(pobTran->srBRec.szExpDate, srCardData.exp);
       }
	}

    if ((pobTran->srBRec.inTranCardType == DEBIT_CARD ||
         pobTran->srBRec.inTranCardType == EBT_CARD) && fTrack2Valid != VS_TRUE)
        return(VS_ERR);

	return (VS_SUCCESS);
}


int inCPACValidateSwipedCard2 (TRANSACTION_OBJECT *pobTran)
{
#ifndef IMAM_REMOVE
int		inResult,
		inStatus = VS_SUCCESS;
		//inTrackNumber; 1.4


VS_BOOL fTrack2Valid = VS_FALSE;
VS_BOOL fTrack1Valid = VS_FALSE;
char	chCardBuffer[CARD_SIZE + 1];
struct	TRACK srCardData; //, srCPACCardData; 1.4 _LINT
/* PFI		pinGetCardBin; 1.4 */
PFI_TO_PSZ_F	pinGetCardBin; // mofified in 1.4
// to be added in 1.4 PFI_PSZ     	pinCheckExpDate;
char	szCardLabel[CLABEL_SIZE + 1];  //CPAC_AMEX
char    szTrackPriority[TRACKS_ALLOWED+1]; //1.4
char    szTracksReq[TRACKS_ALLOWED+1];     //1.4
//PRINTER_OBJECT *pobPrinter;


    if ((pinGetCardBin = inGetFunctionPointer(GET_CARD_BIN2)) == NULL_PFI)
    {
		/**/pdebug (("inGetFunctionPointer pinValSwiped Error"));/**/
        return(VS_ERR);
    }

	/**/pdebug(("--inValidateSwipedCard--"));/**/
	pobTran->srBRec.fManual = VS_FALSE;

/** changed 03/30/99 **/

    inResult = read(hCardReader, chCardBuffer, CARD_SIZE);
    #ifdef SHELL_FLEET

	    for (i=0;i<CARD_SIZE;i++)
		szKbdBuf[i] = chCardBuffer[i]; 	/*	Saritha_b1 added on 2nd July for Shell Application.This value is used in Shellsrc.C file */
    #endif

	if(inResult <= 6)
	{
		/* -- ba1: increment the card read error counter -- */

		INCREMENT_CARD_ERROR;
		vdSGErrorMessage(CARDREAD_ERR_MSG);
		return(VS_ERR);
	}

	/* inTrackNumber = inGetTCTTrackNumber();  //1.4
	if (!(inTrackNumber && BOTH_TRACKS_MASK))
	{
		INCREMENT_CARD_ERROR;
 		vdSGErrorMessage(INVALID_TCT_TRACK_MSG21);
 		return(VS_ERR);
	} */ //1.4
	strcpy ( szTrackPriority , szGetTracks());

	if (strpbrk(szTrackPriority,"123")==NULL_CH) {
		INCREMENT_CARD_ERROR;
 		vdSGErrorMessage(INVALID_TCT_TRACK_MSG21);
 		return(VS_ERR);
	}

	/* Parse card to get acct number to determine if debit
	   handle card parse error */

    inResult = card_parse(chCardBuffer, &srCardData, szTrackPriority);
	if(inResult < 0 )
	{
		INCREMENT_CARD_ERROR;
		vdGetCardParseError ((long)inResult);
 		return(VS_ERR);
	}

 /*   inResult = card_parse(chCardBuffer, &srCPACCardData, "2");
	if(inResult < 0 )
	{
		INCREMENT_CARD_ERROR;
		vdGetCardParseError ((long)inResult);
 		return(VS_ERR);
	}*/ //1.4

/*	strcpy(srCardData.acct, srCPACCardData.acct);  */ // 1.4 card swipe fix

   /* inValInteracDebit (pobTran, &srCardData); */ // commented in core also 1.4

	/**/pdebug(("card parse ret %d", inResult));/**/
    if ((inResult = pinGetCardBin (pobTran, srCardData.acct, VS_FALSE)) <= VS_ERR)
    {
		return(inResult);
	}

#ifdef VXEMVAPP
	strcpy(pobTran->szServiceCode, srCardData.type);
#else
    /* Gw fix from 2.5 - save service code for FPS no auth requires txn.*/
	strcpy(pobTran->srBRec.szAuthCode, srCardData.type);
#endif /* VXEMVAPP */
	strcpy(pobTran->srBRec.szPAN, srCardData.acct);

    /* Form the Last 5 Acct # to Key Structure */
    //strlcpy(pobTran->srBKey.SAcctNum,&pobTran->srBRec.szPAN[strlen(pobTran->srBRec.szPAN) - 5],(FIVE_DIGIT_ACCT + 1));
    pobTran->srBKey.lnLast4 = str2long (&pobTran->srBRec.szPAN[strlen(pobTran->srBRec.szPAN) - LAST4_DIGIT_ACCT]);

	vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
    if((pobTran->srBRec.inTranCardType == DEBIT_CARD ||
        pobTran->srBRec.inTranCardType == EBT_CARD)
 #ifdef PINPAD_DEFINED
            &&
        ((!gfPPadPresent) || (inGetPINPadType() == NO_PINPAD))
#endif /* PINPAD_DEFINED */
        )
    {
        //vdDisplayMessageFromFile( TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
    	vdSGErrorMessage(PINPAD_ERR_MSG21);
		INCREMENT_PINPAD_ERROR;
        return(VS_ERR);
    }
	//strcpy (szTracksReq,szGetTracks());
	strcpy (szTracksReq,szGetTracksRequired());  //spqalog097

	if ( strpbrk(szTrackPriority,"1")!= NULL_CH )
	{
       inResult = card_parse(chCardBuffer, &srCardData, "1");

		if(inResult == 1)
		{
			inStatus = inCheckTrackOneData(&srCardData, inResult);
			if (inStatus == VS_ERR)
        	{
		 		if ((strpbrk(szTrackPriority,"23")==NULL_CH) || (strpbrk(szTracksReq,"1")!=NULL_CH))
    				return VS_ERR;		  /* Error Message is being set in inChecTranOneData */
	        }
    	    else
        	{
            	fTrack1Valid = VS_TRUE;
               	memcpy(pobTran->srBRec.stT1Data, (char *) srCardData.track, TRACK1_SIZE);/* Store Track 1  */
 				pobTran->srBRec.fT1Data = VS_TRUE; //joey /*Added since Track1 was not getting stored in the batch... sowmya*/
 				strcpy(pobTran->srBRec.szCHolder, srCardData.name);
//CPAC_AMEX
				pobTran->srBRec.fCHolder = VS_TRUE;
				strcpy (szCardLabel, szGetCardLabel());
				//vdGetCardLabel(szCardLabel);	/* AMEX expiry date checking not required JD */
				if ((strncmp(szCardLabel, "AMEX", 4) == 0))///ivan
				{
    			if ( fGetExpDtReqd() )
    			{
    				inResult = inValidateExpDate(srCardData.exp);
      				if (inResult != VS_SUCCESS)
	    					return(inResult);
	    			}
	    	    }
    			strcpy(pobTran->srBRec.szExpDate, srCardData.exp);
       		}
       	}
       	else
       		if ((strpbrk(szTrackPriority,"23")==NULL_CH) || (strpbrk(szTracksReq,"1")!=NULL_CH))
       		{
       			vdGetCardParseError((long)inResult);
       			return VS_ERR;
       		}
	}

	if ( fTrack1Valid == VS_FALSE )
    	{
	    strcpy(pobTran->srBRec.szCHolder, "");
	    pobTran->srBRec.fCHolder = VS_FALSE;
	}

	if (strpbrk(szTrackPriority,"2")!=NULL_CH )
	{
		inResult = card_parse(chCardBuffer, &srCardData, "2");
		/**/pdebug(("card parse ret %d", inResult));/**/
		inStatus = inCheckTrackTwoData(&srCardData, inResult);
		if ( inStatus == VS_ERR )
		{
		    if ( fTrack1Valid == VS_FALSE )
    		   	return VS_ERR;	  /* Error Message is being set in inChecTranOneData */

		    /*Praveen_ 20/01/2003_ Fix for track2 Bug*/
           	   if (strpbrk(szTracksReq,"2") != NULL_CH)
                	return VS_ERR;

		}
		else
        {
            fTrack2Valid = VS_TRUE;
    		/**/pdebug(("Track2Valid"));/**/
           	memcpy(pobTran->srBRec.stT2Data, (char *) srCardData.track, TRACK2_SIZE);/* Store Track 2  */
		    pobTran->srBRec.fT2Data = VS_TRUE; //joey /*Added since Track2 was not getting stored in the batch... sowmya*/
		    if ( fTrack1Valid == VS_FALSE )
 					strcpy(pobTran->srBRec.szCHolder, "");
//CPAC_AMEX
			strcpy (szCardLabel, szGetCardLabel());
	//		vdGetCardLabel(szCardLabel);	/* AMEX expiry date checking not required JD */
			if ((strncmp(szCardLabel, "AMEX", 4) != 0))
			{
    		if ( fGetExpDtReqd() )
    		{
				inResult = inValidateExpDate(srCardData.exp);
    			if(inResult != VS_SUCCESS)
	    			return(inResult);
	    	}
			}
/* LENIN  Check above lines */
    		strcpy(pobTran->srBRec.szExpDate, srCardData.exp);
       }
	}

    if ((pobTran->srBRec.inTranCardType == DEBIT_CARD ||
         pobTran->srBRec.inTranCardType == EBT_CARD) && fTrack2Valid != VS_TRUE)
        return(VS_ERR);
#endif //IMAM_REMOVE
	return (VS_SUCCESS);
}

int inCPACValidateSwipedCard3 (TRANSACTION_OBJECT *pobTran)
{
#ifndef IMAM_REMOVE
int		inResult,
		inStatus = VS_SUCCESS;
		//inTrackNumber; 1.4


VS_BOOL fTrack2Valid = VS_FALSE;
VS_BOOL fTrack1Valid = VS_FALSE;
char	chCardBuffer[CARD_SIZE + 1];
struct	TRACK srCardData; //, srCPACCardData; 1.4 _LINT
/* PFI		pinGetCardBin; 1.4 */
PFI_TO_PSZ_F	pinGetCardBin; // mofified in 1.4
// to be added in 1.4 PFI_PSZ     	pinCheckExpDate;
char	szCardLabel[CLABEL_SIZE + 1];  //CPAC_AMEX
char    szTrackPriority[TRACKS_ALLOWED+1]; //1.4
char    szTracksReq[TRACKS_ALLOWED+1];     //1.4
//PRINTER_OBJECT *pobPrinter;


    if ((pinGetCardBin = inGetFunctionPointer(GET_CARD_BIN3)) == NULL_PFI)
    {
		/**/pdebug (("inGetFunctionPointer pinValSwiped Error"));/**/
        return(VS_ERR);
    }

	/**/pdebug(("--inValidateSwipedCard--"));/**/
	pobTran->srBRec.fManual = VS_FALSE;

/** changed 03/30/99 **/

    inResult = read(hCardReader, chCardBuffer, CARD_SIZE);
    #ifdef SHELL_FLEET

	    for (i=0;i<CARD_SIZE;i++)
		szKbdBuf[i] = chCardBuffer[i]; 	/*	Saritha_b1 added on 2nd July for Shell Application.This value is used in Shellsrc.C file */
    #endif

	if(inResult <= 6)
	{
		/* -- ba1: increment the card read error counter -- */

		INCREMENT_CARD_ERROR;
		vdSGErrorMessage(CARDREAD_ERR_MSG);
		return(VS_ERR);
	}

	/* inTrackNumber = inGetTCTTrackNumber();  //1.4
	if (!(inTrackNumber && BOTH_TRACKS_MASK))
	{
		INCREMENT_CARD_ERROR;
 		vdSGErrorMessage(INVALID_TCT_TRACK_MSG21);
 		return(VS_ERR);
	} */ //1.4
	strcpy ( szTrackPriority , szGetTracks());

	if (strpbrk(szTrackPriority,"123")==NULL_CH) {
		INCREMENT_CARD_ERROR;
 		vdSGErrorMessage(INVALID_TCT_TRACK_MSG21);
 		return(VS_ERR);
	}

	/* Parse card to get acct number to determine if debit
	   handle card parse error */

    inResult = card_parse(chCardBuffer, &srCardData, szTrackPriority);
	if(inResult < 0 )
	{
		INCREMENT_CARD_ERROR;
		vdGetCardParseError ((long)inResult);
 		return(VS_ERR);
	}

 /*   inResult = card_parse(chCardBuffer, &srCPACCardData, "2");
	if(inResult < 0 )
	{
		INCREMENT_CARD_ERROR;
		vdGetCardParseError ((long)inResult);
 		return(VS_ERR);
	}*/ //1.4

/*	strcpy(srCardData.acct, srCPACCardData.acct);  */ // 1.4 card swipe fix

   /* inValInteracDebit (pobTran, &srCardData); */ // commented in core also 1.4

	/**/pdebug(("card parse ret %d", inResult));/**/
    if ((inResult = pinGetCardBin (pobTran, srCardData.acct, VS_FALSE)) <= VS_ERR)
    {
		return(inResult);
	}

#ifdef VXEMVAPP
	strcpy(pobTran->szServiceCode, srCardData.type);
#else
    /* Gw fix from 2.5 - save service code for FPS no auth requires txn.*/
	strcpy(pobTran->srBRec.szAuthCode, srCardData.type);
#endif /* VXEMVAPP */
	strcpy(pobTran->srBRec.szPAN, srCardData.acct);

    /* Form the Last 5 Acct # to Key Structure */
    //strlcpy(pobTran->srBKey.SAcctNum,&pobTran->srBRec.szPAN[strlen(pobTran->srBRec.szPAN) - 5],(FIVE_DIGIT_ACCT + 1));
    pobTran->srBKey.lnLast4 = str2long (&pobTran->srBRec.szPAN[strlen(pobTran->srBRec.szPAN) - LAST4_DIGIT_ACCT]);

	vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
    if((pobTran->srBRec.inTranCardType == DEBIT_CARD ||
        pobTran->srBRec.inTranCardType == EBT_CARD)
 #ifdef PINPAD_DEFINED
            &&
        ((!gfPPadPresent) || (inGetPINPadType() == NO_PINPAD))
#endif /* PINPAD_DEFINED */
        )
    {
        //vdDisplayMessageFromFile( TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
    	vdSGErrorMessage(PINPAD_ERR_MSG21);
		INCREMENT_PINPAD_ERROR;
        return(VS_ERR);
    }
	//strcpy (szTracksReq,szGetTracks());
	strcpy (szTracksReq,szGetTracksRequired());  //spqalog097

	if ( strpbrk(szTrackPriority,"1")!= NULL_CH )
	{
       inResult = card_parse(chCardBuffer, &srCardData, "1");

		if(inResult == 1)
		{
			inStatus = inCheckTrackOneData(&srCardData, inResult);
			if (inStatus == VS_ERR)
        	{
		 		if ((strpbrk(szTrackPriority,"23")==NULL_CH) || (strpbrk(szTracksReq,"1")!=NULL_CH))
    				return VS_ERR;		  /* Error Message is being set in inChecTranOneData */
	        }
    	    else
        	{
            	fTrack1Valid = VS_TRUE;
               	memcpy(pobTran->srBRec.stT1Data, (char *) srCardData.track, TRACK1_SIZE);/* Store Track 1  */
 				pobTran->srBRec.fT1Data = VS_TRUE; //joey /*Added since Track1 was not getting stored in the batch... sowmya*/
 				strcpy(pobTran->srBRec.szCHolder, srCardData.name);
//CPAC_AMEX
				pobTran->srBRec.fCHolder = VS_TRUE;
				strcpy (szCardLabel, szGetCardLabel());
				//vdGetCardLabel(szCardLabel);	/* AMEX expiry date checking not required JD */
				if ((strncmp(szCardLabel, "AMEX", 4)== 0))///ivan
				{
    			if ( fGetExpDtReqd() )
    			{
    				inResult = inValidateExpDate(srCardData.exp);
      				if (inResult != VS_SUCCESS)
	    					return(inResult);
	    			}
	    	    }
    			strcpy(pobTran->srBRec.szExpDate, srCardData.exp);
       		}
       	}
       	else
       		if ((strpbrk(szTrackPriority,"23")==NULL_CH) || (strpbrk(szTracksReq,"1")!=NULL_CH))
       		{
       			vdGetCardParseError((long)inResult);
       			return VS_ERR;
       		}
	}

	if ( fTrack1Valid == VS_FALSE )
    	{
	    strcpy(pobTran->srBRec.szCHolder, "");
	    pobTran->srBRec.fCHolder = VS_FALSE;
	}

	if (strpbrk(szTrackPriority,"2")!=NULL_CH )
	{
		inResult = card_parse(chCardBuffer, &srCardData, "2");
		/**/pdebug(("card parse ret %d", inResult));/**/
		inStatus = inCheckTrackTwoData(&srCardData, inResult);
		if ( inStatus == VS_ERR )
		{
		    if ( fTrack1Valid == VS_FALSE )
    		   	return VS_ERR;	  /* Error Message is being set in inChecTranOneData */

		    /*Praveen_ 20/01/2003_ Fix for track2 Bug*/
           	   if (strpbrk(szTracksReq,"2") != NULL_CH)
                	return VS_ERR;

		}
		else
        {
            fTrack2Valid = VS_TRUE;
    		/**/pdebug(("Track2Valid"));/**/
           	memcpy(pobTran->srBRec.stT2Data, (char *) srCardData.track, TRACK2_SIZE);/* Store Track 2  */
		    pobTran->srBRec.fT2Data = VS_TRUE; //joey /*Added since Track2 was not getting stored in the batch... sowmya*/
		    if ( fTrack1Valid == VS_FALSE )
 					strcpy(pobTran->srBRec.szCHolder, "");
//CPAC_AMEX
			strcpy (szCardLabel, szGetCardLabel());
	//		vdGetCardLabel(szCardLabel);	/* AMEX expiry date checking not required JD */
			if ((strncmp(szCardLabel, "AMEX", 4) != 0))
			{
    		if ( fGetExpDtReqd() )
    		{
				inResult = inValidateExpDate(srCardData.exp);
    			if(inResult != VS_SUCCESS)
	    			return(inResult);
	    	}
			}
/* LENIN  Check above lines */
    		strcpy(pobTran->srBRec.szExpDate, srCardData.exp);
       }
	}

    if ((pobTran->srBRec.inTranCardType == DEBIT_CARD ||
         pobTran->srBRec.inTranCardType == EBT_CARD) && fTrack2Valid != VS_TRUE)
        return(VS_ERR);
#endif //IMAM_REMOVE
	return (VS_SUCCESS);
}


int inLoadGetCDTIndex1 (TRANSACTION_OBJECT *pobTran, char *pchPan)
{
#ifndef IMAM_REMOVE
	int inResult, inRetVal, inRecIndex;
	int inNumberOfMatches;
	int inRecNumArray[ 4 ];
	char szChoiceMsg[ MESSAGE_SIZE + 1 ];
	int inIssuer;
	long lnMsgNum;

    /*pdebug(("--inLoadGetCDTIndex--"));*/

    vdSGCurCDTIndex(-1);
	inRetVal = VS_ERR;
	inRecIndex = 0;

    inNumberOfMatches = 0;
    inIssuer = 0;
    memset( szChoiceMsg, 0x00, sizeof( szChoiceMsg ));

    if (strlen(pchPan)<=0)
       return(VS_ERR);

	do
	{
		inResult = inLoadCDTRec( inRecIndex );
		if( inResult == VS_ERR ){
			break;}
             if (inGGCode() == CITI_EPP_SALE){
	 if (inGetStatus() == 1)
		{

			 /* Check by Acct Ranging */

		if ((strncmp(pchPan, szGetPANLo(), min(strlen(pchPan), strlen(szGetPANLo()))) >= 0)
		 && (strncmp(pchPan, szGetPANHi(), min(strlen(pchPan), strlen(szGetPANHi()))) <= 0))
		{
		           if (pobTran->fInteracDebit)
		               {
    			        inRetVal = inRecIndex;
	    	                	break;
		               }

			if ( !(fGetDebitFlag() == VS_FALSE && inGetType() == DEBIT_CARD) &&
			     !(!fGetManEntry() && pobTran->srBRec.fManual == VS_TRUE)
			   )
                          {
			           if ( (inGetType() == DEBIT_CARD ) ||
			                 (inGetType() == EBT_CARD) ||
			                    (inGetIssuerNum() != inIssuer) )
			                 {

					if ( inGetType() != DEBIT_CARD && inGetType() != EBT_CARD )
						inIssuer = inGetIssuerNum();

					inRecNumArray[ inNumberOfMatches++ ] = inRecIndex;

					if(inNumberOfMatches > 1)
			    		szChoiceMsg[ strlen( szChoiceMsg )] = '~';

                                                switch ( inGetType () )
                                                   {
                                          case DEBIT_CARD:
                                              lnMsgNum = DEBIT_CHOICE_MSG5x;
                                                break;
                                          case EBT_CARD:
                                             lnMsgNum = EBT_CHOICE_MSG5x;
                                             break;
                                          case PURCHASE_CARD:
                                             lnMsgNum = PURCHASE_CHOICE_MSG5x;
                                           break;
#ifdef FLEET_DEFINED
						case FLEET_CARD:
							lnMsgNum = FLEET_CHOICE_MSG5x;
							break;
#endif
                                         default:
                                           lnMsgNum = CREDIT_CHOICE_MSG5x;
                                           break;
                                                 }
			        vdGetMessageFromFile( lnMsgNum, &szChoiceMsg[ strlen( szChoiceMsg )]);
			        /*** out with the old
					strcpy( &szChoiceMsg[ strlen( szChoiceMsg )],
			         	srCDTRec.szSCardLabel );
			            ***/

					if( inNumberOfMatches > 3 )
        				break;
    		               }
    		           }
    	           }

	 	}

             	}else
             		{

/* Check by Acct Ranging */

		if ((strncmp(pchPan, szGetPANLo(), min(strlen(pchPan), strlen(szGetPANLo()))) >= 0)
		 && (strncmp(pchPan, szGetPANHi(), min(strlen(pchPan), strlen(szGetPANHi()))) <= 0))
		{
		           if (pobTran->fInteracDebit)
		               {
    			        inRetVal = inRecIndex;
	    	                	break;
		               }

			if ( !(fGetDebitFlag() == VS_FALSE && inGetType() == DEBIT_CARD) &&
			     !(!fGetManEntry() && pobTran->srBRec.fManual == VS_TRUE)
			   )
                          {
			           if ( (inGetType() == DEBIT_CARD ) ||
			                 (inGetType() == EBT_CARD) ||
			                    (inGetIssuerNum() != inIssuer) )
			                 {

					if ( inGetType() != DEBIT_CARD && inGetType() != EBT_CARD )
						inIssuer = inGetIssuerNum();

					inRecNumArray[ inNumberOfMatches++ ] = inRecIndex;

					if(inNumberOfMatches > 1)
			    		szChoiceMsg[ strlen( szChoiceMsg )] = '~';

                                                switch ( inGetType () )
                                                   {
                                          case DEBIT_CARD:
                                              lnMsgNum = DEBIT_CHOICE_MSG5x;
                                                break;
                                          case EBT_CARD:
                                             lnMsgNum = EBT_CHOICE_MSG5x;
                                             break;
                                          case PURCHASE_CARD:
                                             lnMsgNum = PURCHASE_CHOICE_MSG5x;
                                           break;
#ifdef FLEET_DEFINED
						case FLEET_CARD:
							lnMsgNum = FLEET_CHOICE_MSG5x;
							break;
#endif
                                         default:
                                           lnMsgNum = CREDIT_CHOICE_MSG5x;
                                           break;
                                                 }
			        vdGetMessageFromFile( lnMsgNum, &szChoiceMsg[ strlen( szChoiceMsg )]);
			        /*** out with the old
					strcpy( &szChoiceMsg[ strlen( szChoiceMsg )],
			         	srCDTRec.szSCardLabel );
			            ***/

					if( inNumberOfMatches > 3 )
        				break;
    		               }
    		           }
    	           }



				}
		inRecIndex++;

	} while (1);

	/*if (close(hCDTFHandle) < 0)
		inRetVal = VS_ERR;*/

    if( inNumberOfMatches == 1 )
        inRetVal = inRecNumArray[0];

    else if( inNumberOfMatches > 1 )
    {
       // vdClearNonTitleLines();
		vdClearASCII8x21Window(1, 3, 21, 8);
        inRetVal = obDisp.inDO_ChooseOne( NULL,pchGetMsg(DEBIT_CHOOSE_CARD_MSG), szChoiceMsg,
        		inNumberOfMatches, NULL_PFI );

        if (inRetVal==VS_ESCAPE)
        {
            return(VS_ESCAPE);
        }
        inRetVal = inRecNumArray[ inRetVal - 1];
    }

	/* return value is important, not != VS_SUCCESS */
	if (inRetVal < 0)
		vdResetCDTRec();
	else if( inRetVal >= 0 )
	{
    	inLoadCDTRec( inRetVal );
		vdSGCurCDTIndex(inRetVal);  /* Remember the current CDT that is loaded */

    	/* Get the CDT also for card labels */
   	    inGetIssuerRecord(inGetIssuerNum());

    }
	return(inRetVal);
#endif //IMAM_REMOVE
	return VS_SUCCESS;
}

int inLoadGetCDTIndex2 (TRANSACTION_OBJECT *pobTran, char *pchPan)
{
	int inRetVal = VS_SUCCESS;
#ifndef IMAM_REMOVE
	int inResult, inRecIndex;
	int inNumberOfMatches;
	int inRecNumArray[ 4 ];
	char szChoiceMsg[ MESSAGE_SIZE + 1 ];
	int inIssuer;
	long lnMsgNum;

    /*pdebug(("--inLoadGetCDTIndex--"));*/

    vdSGCurCDTIndex(-1);
	inRetVal = VS_ERR;
	inRecIndex = 0;

    inNumberOfMatches = 0;
    inIssuer = 0;
    memset( szChoiceMsg, 0x00, sizeof( szChoiceMsg ));

    if (strlen(pchPan)<=0)
       return(VS_ERR);

	do
	{
		inResult = inLoadCDTRec( inRecIndex );
		if( inResult == VS_ERR )
			break;
 if (inGetStatus() == 2){
        /* Check by Acct Ranging */

		if ((strncmp(pchPan, szGetPANLo(), min(strlen(pchPan), strlen(szGetPANLo()))) >= 0)
		 && (strncmp(pchPan, szGetPANHi(), min(strlen(pchPan), strlen(szGetPANHi()))) <= 0))
		{
		    if (pobTran->fInteracDebit)
		    {
    			inRetVal = inRecIndex;
	    		break;
		    }

			if ( !(fGetDebitFlag() == VS_FALSE && inGetType() == DEBIT_CARD) &&
			     !(!fGetManEntry() && pobTran->srBRec.fManual == VS_TRUE)
			   )
            {
			    if ( (inGetType() == DEBIT_CARD ) ||
			         (inGetType() == EBT_CARD) ||
			         (inGetIssuerNum() != inIssuer) )
			    {

					if ( inGetType() != DEBIT_CARD && inGetType() != EBT_CARD )
						inIssuer = inGetIssuerNum();

					inRecNumArray[ inNumberOfMatches++ ] = inRecIndex;

					if(inNumberOfMatches > 1)
			    		szChoiceMsg[ strlen( szChoiceMsg )] = '~';

                    switch ( inGetType () )
                    {
                        case DEBIT_CARD:
                            lnMsgNum = DEBIT_CHOICE_MSG5x;
                            break;
                        case EBT_CARD:
                            lnMsgNum = EBT_CHOICE_MSG5x;
                            break;
                        case PURCHASE_CARD:
                            lnMsgNum = PURCHASE_CHOICE_MSG5x;
                            break;
#ifdef FLEET_DEFINED
						case FLEET_CARD:
							lnMsgNum = FLEET_CHOICE_MSG5x;
							break;
#endif
                        default:
                            lnMsgNum = CREDIT_CHOICE_MSG5x;
                            break;
                    }
			        vdGetMessageFromFile( lnMsgNum, &szChoiceMsg[ strlen( szChoiceMsg )]);
			        /*** out with the old
					strcpy( &szChoiceMsg[ strlen( szChoiceMsg )],
			         	srCDTRec.szSCardLabel );
			            ***/

					if( inNumberOfMatches > 3 )
        				break;
    		    }
    		}
    	}
 	}
		inRecIndex++;

	} while (1);

	/*if (close(hCDTFHandle) < 0)
		inRetVal = VS_ERR;*/

    if( inNumberOfMatches == 1 )
        inRetVal = inRecNumArray[0];

    else if( inNumberOfMatches > 1 )
    {
       // vdClearNonTitleLines();
		vdClearASCII8x21Window(1, 3, 21, 8);
        inRetVal = obDisp.inDO_ChooseOne( NULL,pchGetMsg(DEBIT_CHOOSE_CARD_MSG), szChoiceMsg,
        		inNumberOfMatches, NULL_PFI );

        if (inRetVal==VS_ESCAPE)
        {
            return(VS_ESCAPE);
        }
        inRetVal = inRecNumArray[ inRetVal - 1];
    }

	/* return value is important, not != VS_SUCCESS */
	if (inRetVal < 0)
		vdResetCDTRec();
	else if( inRetVal >= 0 )
	{
    	inLoadCDTRec( inRetVal );
		vdSGCurCDTIndex(inRetVal);  /* Remember the current CDT that is loaded */

    	/* Get the CDT also for card labels */
   	    inGetIssuerRecord(inGetIssuerNum());

    }
#endif //IMAM_REMOVE
	return(inRetVal);
}

int inLoadGetCDTIndex3 (TRANSACTION_OBJECT *pobTran, char *pchPan)
{
	int inRetVal = VS_SUCCESS;
#ifndef IMAM_REMOVE
	int inResult, inRecIndex;
	int inNumberOfMatches;
	int inRecNumArray[ 4 ];
	char szChoiceMsg[ MESSAGE_SIZE + 1 ];
	int inIssuer;
	long lnMsgNum;

    /*pdebug(("--inLoadGetCDTIndex--"));*/

    vdSGCurCDTIndex(-1);
	inRetVal = VS_ERR;
	inRecIndex = 0;

    inNumberOfMatches = 0;
    inIssuer = 0;
    memset( szChoiceMsg, 0x00, sizeof( szChoiceMsg ));

    if (strlen(pchPan)<=0)
       return(VS_ERR);

	do
	{
		inResult = inLoadCDTRec( inRecIndex );
		if( inResult == VS_ERR )
			break;
 if (inGetStatus() == 3){
        /* Check by Acct Ranging */

		if ((strncmp(pchPan, szGetPANLo(), min(strlen(pchPan), strlen(szGetPANLo()))) >= 0)
		 && (strncmp(pchPan, szGetPANHi(), min(strlen(pchPan), strlen(szGetPANHi()))) <= 0))
		{
		    if (pobTran->fInteracDebit)
		    {
    			inRetVal = inRecIndex;
	    		break;
		    }

			if ( !(fGetDebitFlag() == VS_FALSE && inGetType() == DEBIT_CARD) &&
			     !(!fGetManEntry() && pobTran->srBRec.fManual == VS_TRUE)
			   )
            {
			    if ( (inGetType() == DEBIT_CARD ) ||
			         (inGetType() == EBT_CARD) ||
			         (inGetIssuerNum() != inIssuer) )
			    {

					if ( inGetType() != DEBIT_CARD && inGetType() != EBT_CARD )
						inIssuer = inGetIssuerNum();

					inRecNumArray[ inNumberOfMatches++ ] = inRecIndex;

					if(inNumberOfMatches > 1)
			    		szChoiceMsg[ strlen( szChoiceMsg )] = '~';

                    switch ( inGetType () )
                    {
                        case DEBIT_CARD:
                            lnMsgNum = DEBIT_CHOICE_MSG5x;
                            break;
                        case EBT_CARD:
                            lnMsgNum = EBT_CHOICE_MSG5x;
                            break;
                        case PURCHASE_CARD:
                            lnMsgNum = PURCHASE_CHOICE_MSG5x;
                            break;
#ifdef FLEET_DEFINED
						case FLEET_CARD:
							lnMsgNum = FLEET_CHOICE_MSG5x;
							break;
#endif
                        default:
                            lnMsgNum = CREDIT_CHOICE_MSG5x;
                            break;
                    }
			        vdGetMessageFromFile( lnMsgNum, &szChoiceMsg[ strlen( szChoiceMsg )]);
			        /*** out with the old
					strcpy( &szChoiceMsg[ strlen( szChoiceMsg )],
			         	srCDTRec.szSCardLabel );
			            ***/

					if( inNumberOfMatches > 3 )
        				break;
    		    }
    		}
    	}
 	}

		inRecIndex++;

	} while (1);

	/*if (close(hCDTFHandle) < 0)
		inRetVal = VS_ERR;*/

    if( inNumberOfMatches == 1 )
        inRetVal = inRecNumArray[0];

    else if( inNumberOfMatches > 1 )
    {
       // vdClearNonTitleLines();
		vdClearASCII8x21Window(1, 3, 21, 8);
        inRetVal = obDisp.inDO_ChooseOne( NULL,pchGetMsg(DEBIT_CHOOSE_CARD_MSG), szChoiceMsg,
        		inNumberOfMatches, NULL_PFI );

        if (inRetVal==VS_ESCAPE)
        {
            return(VS_ESCAPE);
        }
        inRetVal = inRecNumArray[ inRetVal - 1];
    }

	/* return value is important, not != VS_SUCCESS */
	if (inRetVal < 0)
		vdResetCDTRec();
	else if( inRetVal >= 0 )
	{
    	inLoadCDTRec( inRetVal );
		vdSGCurCDTIndex(inRetVal);  /* Remember the current CDT that is loaded */

    	/* Get the CDT also for card labels */
   	    inGetIssuerRecord(inGetIssuerNum());

    }
#endif //IMAM_REMOVE
	return(inRetVal);
}


int inValidateManualCardNo1 (TRANSACTION_OBJECT *pobTran,char *pchAcctNum)
{
int		inResult;
PFI_TO_PSZ_F		pinGetCardBin;

	/* set the GDS manual entry flag */
	pobTran->srBRec.fManual = VS_TRUE;

    if ((pinGetCardBin = inGetFunctionPointer(GET_CARD_BIN1)) == NULL_PFI)
    {
		//pdebug (("inGetFunctionPointer pinValSwiped Error"));
        return(VS_ERR);
    }

    //pdebug(("--inValidateManualCardNo--"));
	inResult = pinGetCardBin(pobTran, pchAcctNum, VS_TRUE );
    switch ( inGetType() )
    {
        case DEBIT_CARD:
    		pobTran->srBRec.inTranCardType = DEBIT_CARD; /* Set Debit Active */
    		break;
        case PURCHASE_CARD:
            pobTran->srBRec.inTranCardType = PURCHASE_CARD; /* Set Purchase */
            break;
        case CREDIT_CARD:
        	pobTran->srBRec.inTranCardType = CREDIT_CARD; /* Set Credit Active */
            break;
		case FLEET_CARD:
			pobTran->srBRec.inTranCardType = FLEET_CARD; /* Set Fleet Active */
			break;
        case EBT_CARD:  /* Can Manually enter EBT Cards but still must have PINPad and Printer */
        	pobTran->srBRec.inTranCardType = EBT_CARD; /* Set EBT Active */
            break;
    } /* end switch card type */

	if ( inResult != VS_SUCCESS )
		return(inResult);

	if(fGetPinpadRequired()
#ifdef PINPAD_DEFINED
            &&
        ((!gfPPadPresent) || (inGetPINPadType() == NO_PINPAD))
#endif /* PINPAD_DEFINED */
        )
    {
        //vdDisplayMessageFromFile( TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
    	vdSGErrorMessage(PINPAD_ERR_MSG21);
		INCREMENT_PINPAD_ERROR;
        return(VS_ERR);

    } /* end if CDT pinpad required */


	if (fGetPrntrRequired())
	{
        if (inGetPrinterType() == NOPRINTER  ||
            !fGetEnablePrinter() || inChkPrinterStatus(&obPrinter) != VS_SUCCESS)
        {
            //vdDisplayMessageFromFile( TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);

        	vdSGErrorMessage(PRINTER_ERR_MSG21);
            return(VS_ERR);
		}
	} /* end if CDT printer required */


	return(VS_SUCCESS);
} /* inValidateManualCardNo() */


int inValidateManualCardNo2 (TRANSACTION_OBJECT *pobTran,char *pchAcctNum)
{
#ifndef IMAM_REMOVE
int		inResult;
PFI_TO_PSZ_F		pinGetCardBin;

	/* set the GDS manual entry flag */
	pobTran->srBRec.fManual = VS_TRUE;

    if ((pinGetCardBin = inGetFunctionPointer(GET_CARD_BIN2)) == NULL_PFI)
    {
		//pdebug (("inGetFunctionPointer pinValSwiped Error"));
        return(VS_ERR);
    }

    //pdebug(("--inValidateManualCardNo--"));
	inResult = pinGetCardBin(pobTran, pchAcctNum, VS_TRUE );
    switch ( inGetType() )
    {
        case DEBIT_CARD:
    		pobTran->srBRec.inTranCardType = DEBIT_CARD; /* Set Debit Active */
    		break;
        case PURCHASE_CARD:
            pobTran->srBRec.inTranCardType = PURCHASE_CARD; /* Set Purchase */
            break;
        case CREDIT_CARD:
        	pobTran->srBRec.inTranCardType = CREDIT_CARD; /* Set Credit Active */
            break;
		case FLEET_CARD:
			pobTran->srBRec.inTranCardType = FLEET_CARD; /* Set Fleet Active */
			break;
        case EBT_CARD:  /* Can Manually enter EBT Cards but still must have PINPad and Printer */
        	pobTran->srBRec.inTranCardType = EBT_CARD; /* Set EBT Active */
            break;
    } /* end switch card type */

	if ( inResult != VS_SUCCESS )
		return(inResult);

	if(fGetPinpadRequired()
#ifdef PINPAD_DEFINED
            &&
        ((!gfPPadPresent) || (inGetPINPadType() == NO_PINPAD))
#endif /* PINPAD_DEFINED */
        )
    {
        //vdDisplayMessageFromFile( TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
    	vdSGErrorMessage(PINPAD_ERR_MSG21);
		INCREMENT_PINPAD_ERROR;
        return(VS_ERR);

    } /* end if CDT pinpad required */


	if (fGetPrntrRequired())
	{
        if (inGetPrinterType() == NOPRINTER  ||
            !fGetEnablePrinter() || inChkPrinterStatus(&obPrinter) != VS_SUCCESS)
        {
            //vdDisplayMessageFromFile( TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);

        	vdSGErrorMessage(PRINTER_ERR_MSG21);
            return(VS_ERR);
		}
	} /* end if CDT printer required */

#endif //IMAM_REMOVE
	return(VS_SUCCESS);
} /* inValidateManualCardNo() */

int inValidateManualCardNo3 (TRANSACTION_OBJECT *pobTran,char *pchAcctNum)
{
#ifndef IMAM_REMOVE
int		inResult;
PFI_TO_PSZ_F		pinGetCardBin;

	/* set the GDS manual entry flag */
	pobTran->srBRec.fManual = VS_TRUE;

    if ((pinGetCardBin = inGetFunctionPointer(GET_CARD_BIN3)) == NULL_PFI)
    {
		//pdebug (("inGetFunctionPointer pinValSwiped Error"));
        return(VS_ERR);
    }

    //pdebug(("--inValidateManualCardNo--"));
	inResult = pinGetCardBin(pobTran, pchAcctNum, VS_TRUE );
    switch ( inGetType() )
    {
        case DEBIT_CARD:
    		pobTran->srBRec.inTranCardType = DEBIT_CARD; /* Set Debit Active */
    		break;
        case PURCHASE_CARD:
            pobTran->srBRec.inTranCardType = PURCHASE_CARD; /* Set Purchase */
            break;
        case CREDIT_CARD:
        	pobTran->srBRec.inTranCardType = CREDIT_CARD; /* Set Credit Active */
            break;
		case FLEET_CARD:
			pobTran->srBRec.inTranCardType = FLEET_CARD; /* Set Fleet Active */
			break;
        case EBT_CARD:  /* Can Manually enter EBT Cards but still must have PINPad and Printer */
        	pobTran->srBRec.inTranCardType = EBT_CARD; /* Set EBT Active */
            break;
    } /* end switch card type */

	if ( inResult != VS_SUCCESS )
		return(inResult);

	if(fGetPinpadRequired()
#ifdef PINPAD_DEFINED
            &&
        ((!gfPPadPresent) || (inGetPINPadType() == NO_PINPAD))
#endif /* PINPAD_DEFINED */
        )
    {
        //vdDisplayMessageFromFile( TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
    	vdSGErrorMessage(PINPAD_ERR_MSG21);
		INCREMENT_PINPAD_ERROR;
        return(VS_ERR);

    } /* end if CDT pinpad required */


	if (fGetPrntrRequired())
	{
        if (inGetPrinterType() == NOPRINTER  ||
            !fGetEnablePrinter() || inChkPrinterStatus(&obPrinter) != VS_SUCCESS)
        {
            //vdDisplayMessageFromFile( TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);

        	vdSGErrorMessage(PRINTER_ERR_MSG21);
            return(VS_ERR);
		}
	} /* end if CDT printer required */

#endif //IMAM_REMOVE
	return(VS_SUCCESS);
} /* inValidateManualCardNo() */





int inCITISelectAndLoadHost(TRANSACTION_OBJECT *pobTran)
{
	int inResult = VS_FALSE;

	if (inSelectTran == EPP)
		inResult = inRunFunction(pobTran, EPP_SELECT_HOST);

	else
		inResult = inRunFunction(pobTran, SELECT_AND_LOAD_HOST);

	return(inResult);
}


int inCITIDisplayAtIdle(TRANSACTION_OBJECT* pobTran) {
    char chTimeBuff[FORMATTED_TIME_SIZE + 1];
    char chDateBuff[FORMATTED_DATE_SIZE + 1];

    // Check idle timeout
    //vdCheckIdleTimeOut(); //: Move to IMAM Idle

    /*
     *      Update Date/Time Display
     */

    vdDisplayDEMO(); //LIEM TMP DISABLE FOR BNI

    // Battery and Antenna
    // vdDisplayWireless(); //LIEM DISABLE, AS WE HAVE OUR OWN
    // vdDisplayBattery(); //LIEM DISABLE, AS WE HAVE OUR OWN



#ifdef MESSENGER_DEFINED
    vdDisplayMail();
#endif

    vdDisplayDockStatus(); //kv1 debug

    if (!inNoDisp) {
        if (fGetKeyboardLock())
            vdDispStrCentered(obDisp.szLockedMsg, obDisp.inTitleLine, CLR_EOL);
        else if (fRootMenu()) {
            static int inCurSS = 60;
            static VS_BOOL fDisplayLogo = VS_TRUE;
            int inSS = 0;

            vdGetTime(chTimeBuff);
            inSS = strn2int(chTimeBuff + 4, 2);

            if (((inCurSS != inSS) && (inSS % 3) == 0) || fDisplayLogoNow) {
                if (get_battery_status() == CRITICAL_LEVEL && get_dock_status() == HANDHELD_UNDOCKED) {
                    error_tone();
                    vdDelay(BEEP_DELAY);
                    error_tone();
                    vdDelay(BEEP_DELAY);
                    error_tone();
                }

                inCurSS = inSS;
                if (fDisplayLogo || fDisplayLogoNow) {
					if (lnImamMenuItem >= 1 && lnImamMenuItem <= 4){ // to add checking menustatus
						vdPutIdleLogo();
						fDisplayLogoNow = fDisplayLogo = VS_FALSE;
					}
                } else /** /if ( 0 ) // KV1 Debug - Static Idle Logo Display */ {
                    if (fDisplayIdleMenu) {
                        //pdebug (("fDisplayIdleMenu == TRUE"));
                        vdSelectMenu(ROOT_MENU_ID);
                    }
					if (lnImamMenuItem >= 1 && lnImamMenuItem <= 4){ // to add checking menustatus
						fDisplayIdleIcons = VS_TRUE;
						/* Return to idle if failed */
						vdClearLogoLine();
						/* display date */
						vdGetDate(chDateBuff, YYMMDD);
						vdFormatDate(chDateBuff);
						/* display time */
						vdGetTime(chTimeBuff);
						vdFormatTime(chTimeBuff);
						chTimeBuff[5] = NULL_CH;
						//vdSetIdleFont(VS_FALSE);
						vdDisplayAt(obDisp.inHomeCol, obDisp.inTitleLine, chDateBuff, NO_CLEAR);
						vdDispStrAtRight(chTimeBuff, obDisp.inTitleLine, NO_CLEAR);
						//vdResetIdleFont(VS_FALSE);
						fDisplayLogo = VS_TRUE;
					}
                }
            }
            // Request Wireless Signal Stength
            else if ((inCurSS != inSS) && (inSS == 7 || inSS == 28 || inSS == 47)) {
                if (srGDS.fWirelessActive) {
#ifdef MOBITEX_DEFINED
                    if (obCommunication.inLinkType == MOBITEX_COMM) {
                        extern char gchFPacketFlag;

                        gchFPacketFlag = 0x00;
                        //pdebug(("Send SS FA Packet"));
                        inSendMobitexFAPacket();
                    }
#endif
                }
            }
        }
    }

    return (VS_SUCCESS);
}


int inCITIStartCardTxn (TRANSACTION_OBJECT *pobTran)
{
	char szMessage [MESSAGE_SIZE + 1];

    if ((inGGCode() != SALE) && (CHK_CARD_RDR() != 0)&&(inGGCode() != CITI_EPP_SALE)) {  // Clear any pending mag swipe data
		// Only if not the SALE///ivan
		vdFlushCardBuffer();
    }
		
	if ((inGGCode() != PHONE) && (CHK_CARD_RDR()==0)
#ifdef ICC_DEFINED // 1.4
       && (Get_Card_State(CUSTOMER_CARD) != CARD_PRESENT)
#endif
       ){
		vdClearASCII8x21Window(1, 3, 21, 8);  // Clear the screen except the trn name
		/*if(inGGOpCode() == CITI_MANUAL_SALE_OPERATION)
		vdGetMessageFromFile (CITI_ENTER_MSG, szMessage);
		else*/
		#ifdef VXEMVAPP
		if((lnTranTitleMessage == SALE_MSG) ||(lnTranTitleMessage == AUTH_ONLY_ITEM_MSG15) ||
			(lnTranTitleMessage == PRE_AUTH_MSG) || (lnTranTitleMessage == REFUND_OFFLINE_MSG) ||
			(lnTranTitleMessage == SALE_OFFLINE_MSG) || (lnTranTitleMessage == CITI_EPP_SALE_MSG) ||
			(lnTranTitleMessage == CITI_EPP_CASH_MSG) || (lnTranTitleMessage == CITI_EPP_CASHBACK_MSG) ||
			(lnTranTitleMessage == CITI_CARD_VERIFY_MSG) || //jrd 05212005
			(lnTranTitleMessage == IMAM_CARDVER_MSG) || //
			(lnTranTitleMessage == IMAM_AUTHONLY_MSG)) //LIEM
				vdGetMessageFromFile(EMV_INSERT_MSG, szMessage);
			else
			#endif /* VXEMVAPP */
			 	vdGetMessageFromFile (SWIPE_MSG, szMessage);

		if (getgrid() == 0)
			vdDisplayAt (1, 2, szMessage, CLR_EOL);
		else
			vdDisplayAt (1, 3, szMessage, CLR_EOL);
	}

	if (CHK_CARD_RDR()==0
#ifdef ICC_DEFINED //1.4
		&& (Get_Card_State(CUSTOMER_CARD) != CARD_PRESENT)
#endif
        ){
		vdGetMessageFromFile (CPAC_PAN_MESSAGE, szMessage);
		if (getgrid() == 0)
			vdDisplayAt (1, 3, szMessage, CLR_EOL);
		else
			vdDisplayAt (1, 5, szMessage, CLR_EOL);
	}

	vdClear_8X21_Window(1, 8, 21, inImamLineNumber);
	if (getgrid() == 0)
		vdClear_8X21_Window(1, 7, 21, inImamLineNumber);   // clear the seventh line also

	return (VS_SUCCESS);
}


int inCITIPrintReceiptTop(TRANSACTION_OBJECT* pobTran) {

	DB_FILE dbReprintFile;



    LOG_PRINTFF((0x8L, "Print start"));
    if (pobTran->fPreprinted)
        return(VS_SUCCESS);

	/* Place the Reprint Functionality at the beginning of printing the receipt jrd 01152004*/



            if (db_open(&dbReprintFile, REPRINT_FILE_NAME, SIZE_BATCH_KEY, (O_TRUNC | O_CREAT | O_RDWR)) < 0)

        return(VS_ERR);



    if (inWriteBatchData(&dbReprintFile, &pobTran->srBKey, &pobTran->srBRec, DB_APPEND) != VS_SUCCESS) {


        vdSGErrorMessage(BATCH_ERR_MSG);

        return(VS_ERR);

    }



    if (inCloseBatch(&dbReprintFile) != VS_SUCCESS)
    {

        vdSGErrorMessage(BATCH_ERR_MSG);

	}


    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }


    if (!pobTran->srTRTRec.PrintReceipt && !(pobTran->srBRec.inPrintOption & PRT_DUPLICATE))
        return(VS_SUCCESS);

    if (((inGGCode() == PRE_COMP) && (!fPrintCloseTab(pobTran))) || ((inGGCode() == PRE_AUTH) && (fGetOpenTabOptRec() == VS_FALSE))) {
        vdDisplayMessageFromFile(NO_RCPT_ERR_MSG, WARNING_MSG);
        pause(50);
        return(VS_SUCCESS);
    }

    if (fGetEnablePrinter())
        vdDisplayMessageFromFile(PRINTING_MSG, STATUS_MSG);

    /*
        Preprint up to account number
    */

    inPrintReceiptHeader(pobTran);

    /* LENIN CPAC #if TBD_CPAC */
    vdSetPrintReceiptConditions(pobTran);
    /* LENIN CPAC #endif  CPAC_TBD */

    /*LENIN CPAC  #if TBD_CPAC */
    vdCITIMakeReceiptTop(pobTran);
    /* LENIN #endif  CPAC_TBD */

    vdCPACMakeReceiptAfterResp(pobTran);
    //vdEMVMakeReceiptAfterResp(pobTran);   // jrd 05222005
    pad(srRcpt.unFrm.srReceipt.szSTAN, srRcpt.unFrm.srReceipt.szSTAN, '0', 6, RIGHT);
    pad(srRcpt.szInvNum, srRcpt.szInvNum, '0', 6, RIGHT);  // Inv_num padding CPAC_CITI_PHIL

#ifdef CITI_PHIL
    //Kelvin_F2 --- start: no need to mask MID
#ifdef MASK_TID_AND_MID
    vdMaskCitiMTID();
#endif
    //Kelvin_F2 --- end: no need to mask MID
#endif /* CITI_PHIL */

    /* LENIN CPAC #if TBD_CPAC */
    inPrintReceiptHeader2(&obPrinter, pobTran);
    /* LENIN CPAC #endif  CPAC_TBD */

    pobTran->fPreprinted = VS_TRUE;


    ///*Saritha_b1.............Start...........Amex Roc Printing */
    //#ifdef AMEX_SOC

    //  strcpy(srRcpt.unFrm.srReceipt.szGenBuf2, (char*)srISO.pszField62);

    //if (inPrintLines(&obPrinter, AMEX_SOC_PRINT_START, AMEX_SOC_PRINT_END, NO_BL_LINE, 0L) != VS_SUCCESS)
    //  return(VS_ERROR);

    //#endif  /*   AMEX_ROC */

    /*Saritha_b1.............End...........Amex Roc Printing */
    return(VS_SUCCESS);
}


int inCITIPrintReceiptBottom (TRANSACTION_OBJECT *pobTran)
	{

		int ACLen=0;
		int TVRLen=0;
		char btAP[10];
		char btTVR[10];
		char szACrypt[30];
		char szTVRVal[20];

	char   szAXAPHost[5 + 1];
		//jhia AMEX
	long lnSignLineCondition;
       unsigned char btTmp[64];
	char szAsciibuff[32+1];
       lnSignLineCondition = 0L;
	//jhia AMEX



    //int hReprint;  CPAC_LINT_RMD
    //DB_FILE dbReprintFile;
    #ifdef SHELL_FLEET
    		unsigned char stCardType[CARD_TYPE_SIZE + 1]; //For SHELL Host
    		int inTranCardType;
    #endif

    /**/pdebug(("--inPrintReceiptBottom--"));/**/

    #ifdef DOWNLOAD_MULTIPLE_LOGO
		inMultipleDownloadLogo(1);
    #endif

        if (inGetPrinterType() == NOPRINTER  || !fGetEnablePrinter())
        {
            return(VS_SUCCESS);
        }
        /* vdCPACMakeReceiptAfterResp(pobTran); */
/*CPAC LENIN #if TBD_CPAC  */
        vdSetPrintReceiptConditions(pobTran);
/* CPAC LENIN #endif  TBD_CPAC */

        if (!pobTran->srTRTRec.PrintReceipt && !(pobTran->srBRec.inPrintOption & PRT_DUPLICATE))
            return(VS_SUCCESS);

        if ((inGGCode() == PRE_COMP) && (!fPrintCloseTab(pobTran)))
           return(VS_SUCCESS);

        if ((inGGCode() == PRE_AUTH) && (fGetOpenTabOptRec() == VS_FALSE))
           return(VS_SUCCESS);

        if (fGetEnablePrinter())
		{
			vdDisplayAt(1,inImamLineNumber,"PRINTING ...", NO_CLEAR);

		}
	if (pobTran->srBRec.inChipStatus==EMV_CARD)
	 {
		//KiaSoon 06022006: To print TC on APPL CRYTO for receipt instead of ARQC
		//if((inGGCode() == PRE_AUTH) || (inGGCode() == AUTH_ONLY))  //LIEM DISABLE THIS AUTH EXCEPTION
		//{
		//	ACLen=inAddDataToEMVPacket(TAG_9F26_APPL_CRYPTOGRAM, (unsigned char *)&btAP[0]);
		//	TVRLen=inAddDataToEMVPacket(TAG_9500_TVR, (unsigned char *)&btTVR[0]);	
		//}
		//else
		{
			ACLen = inGetDataLengthFromBatch(pobTran, FID_EMV_TAG_9F26_APP_CRYPTOGRAM_LEN_2ND);
			inGetDataFromBatchToEMVPacket(pobTran, FID_EMV_TAG_9F26_APP_CRYPTOGRAM_2ND, ACLen, (unsigned char *)&btAP[0]);	
			TVRLen = inGetDataLengthFromBatch(pobTran, FID_EMV_TAG_95_TVR_LEN_2ND);
		 	inGetDataFromBatchToEMVPacket(pobTran, FID_EMV_TAG_95_TVR_2ND, TVRLen, (unsigned char *)&btTVR[0]);
		}
		//ACLen = inGetDataLengthFromBatch(pobTran, FID_EMV_TAG_9F26_APP_CRYPTOGRAM_LEN);
		//inGetDataFromBatchToEMVPacket(pobTran, FID_EMV_TAG_9F26_APP_CRYPTOGRAM, ACLen, (unsigned char *)&btAP[0]);
		//TVRLen = inGetDataLengthFromBatch(pobTran, FID_EMV_TAG_95_TVR_LEN);
		// inGetDataFromBatchToEMVPacket(pobTran, FID_EMV_TAG_95_TVR, TVRLen, (unsigned char *)&btTVR[0]);

		memset(szTVRVal, 0x00,sizeof(szTVRVal));
		hex_2_asc((BYTE *) &szTVRVal[0], (BYTE *)btTVR, TVRLen);

		memset(srRcpt.unFrm.srReceipt.szTVRValue,0x00,sizeof(srRcpt.unFrm.srReceipt.szTVRValue));
		memcpy(srRcpt.unFrm.srReceipt.szTVRValue, &szTVRVal[4],strlen(szTVRVal));


		memset(szACrypt, 0x00,sizeof(szACrypt));
	 	hex_2_asc((BYTE *) &szACrypt[0], (BYTE *)btAP, ACLen);

		memset(srRcpt.unFrm.srReceipt.szAppCrypt,0x00,sizeof(srRcpt.unFrm.srReceipt.szAppCrypt));
		memcpy(srRcpt.unFrm.srReceipt.szAppCrypt, &szACrypt[6],strlen(szACrypt));

		memset(szAXAPHost, 0, sizeof(szAXAPHost));
		inGetBatchFieldData(&pobTran->srBRec, AXAP_HOST, (unsigned char *)szAXAPHost, 5);
		if(strcmp((char*)szAXAPHost, "AXAP") == 0)
		{

			memset(szTVRVal, 0x00,sizeof(szTVRVal));
			inGetBatchFieldData(&pobTran->srBRec, AXAP_TVR, (unsigned char *)szTVRVal, 14);
			memset(szACrypt, 0x00,sizeof(szACrypt));
			inGetBatchFieldData(&pobTran->srBRec, AXAP_APPL_CRYPT, (unsigned char *)szACrypt, 22);
			memset(srRcpt.unFrm.srReceipt.szTVRValue,0x00,sizeof(srRcpt.unFrm.srReceipt.szTVRValue));
			memcpy(srRcpt.unFrm.srReceipt.szTVRValue, &szTVRVal[4],strlen(szTVRVal));
			memset(srRcpt.unFrm.srReceipt.szAppCrypt,0x00,sizeof(srRcpt.unFrm.srReceipt.szAppCrypt));
			memcpy(srRcpt.unFrm.srReceipt.szAppCrypt, &szACrypt[6],strlen(szACrypt));

		}


		/*code here the checking of no signature*/



	 } else {
		memset(srRcpt.unFrm.srReceipt.szTVRValue,0x00,sizeof(srRcpt.unFrm.srReceipt.szTVRValue));
		strcpy(srRcpt.unFrm.srReceipt.szTVRValue, "-");
		memset(srRcpt.unFrm.srReceipt.szAppCrypt,0x00,sizeof(srRcpt.unFrm.srReceipt.szAppCrypt));
		strcpy(srRcpt.unFrm.srReceipt.szAppCrypt, "-");
	 }

	//jhia
//for amex to print AID and App Label
//#ifdef AMEX_EMV
inLoadHDTRec(shGetHostGroupRef());
 if (pobTran->srBRec.inChipStatus==EMV_CARD /*&& strcmp(szGetHostName(),"AXAP")==0  LIEM DISABLE*/)
 {
	lnMiddleCondition|=0x200L;
	memset(btTmp,0x00,sizeof(btTmp));
	inGetBatchFieldData((BATCH_REC * )&pobTran->srBRec, FID_EMV_TAG_4F_AID, (unsigned char *)btTmp, 16);
	SVC_HEX_2_DSP((char  *)btTmp,szAsciibuff,8);
    //memcpy(srRcpt.unFrm.srReceipt.szGenBuf1,szAsciibuff,16); LIEM
	memcpy(srRcpt.unFrm.srReceipt.szAIDValue,szAsciibuff,16);
 } else {
	strcpy(srRcpt.unFrm.srReceipt.szAIDValue, "-");
 }


//jhia
//#endif

	if(fGetDemoMode() == VS_TRUE){
		strcpy(srRcpt.unFrm.srReceipt.szRefCustNumber, "010203040506");
	}
/*		else if ( pobTran->srBKey.fOffline==VS_TRUE) {
			strcpy(srRcpt.unFrm.srReceipt.szRefCustNumber, " ");
		} LENIN COMMENTED THE CODE */
	else
       	vdGetCPACRetRefNum (&pobTran->srBRec,(unsigned char *)srRcpt.unFrm.srReceipt.szRefCustNumber);
											// CPAC_LINT type-casted 2nd argument with (unsigned char *)
      //  strcpy(srRcpt.unFrm.srReceipt.szRefCustNumber,srISO.pszField37);

      vdGetCPACUserInvNum(&pobTran->srBRec, (unsigned char *)srRcpt.szTipPct1);
	sprintf(srRcpt.unFrm.srReceipt.szGenBuf5, "%ld", pobTran->srBRec.lnSTAN);  										// CPAC_LINT type-casted 2nd argument with (unsigned char *)

	{// in inCPACPrintReceiptMiddle(PRINTER_OBJECT* obPrinter) 
		lnMiddleCondition = 0L;
		{
			if ((pobTran->srTRTRec.TransactionCode == REFUND_OFFLINE) || (pobTran->srBRec.inCode == REFUND_OFFLINE)){
				strcpy((char *)srRcpt.szTransName, "REFUND OFFLINE");
				if (pobTran->srBKey.fVoided){
					strcpy((char *)srRcpt.szTransName, "VOID REFUND OFFLINE");
				}
			}
		}
		if (strlen(srRcpt.szTransName) > 11) { //LIEM : if trans name too long make it small font
			lnMiddleCondition |= 0x2L;   
		}
		if (strlen(srRcpt.szTransName) > 21) { //LIEM : if trans name too long truncate it
			srRcpt.szTransName[21] = 0x00;
		}
		if (strlen(srRcpt.unFrm.srReceipt.szCHolder)>0) {
			lnMiddleCondition |= 0x20L;
		}
	}
	if (pobTran->srBRec.inChipStatus==EMV_CARD){ // for EMV Data Printing
		lnMiddleCondition |= 0x200L;   
	}

   	if (inCPACPrintReceiptMiddle(&obPrinter))
       	    return(VS_ERR);
/* CPAC LENIN #if TBD_CPAC */
        vdSetPrintReceiptConditions(pobTran);
/* CPAC LENIN #endif  TBD_CPAC */
      //  if (inGGCode() == AUTH_ONLY)//1.4
       //  	lnMiddleCondition &= 0xFFFBFFFF;

#ifdef SHELL_FLEET
	memcpy(stCardType, szKbdBuf + CARD_TYPE_OFFSET, CARD_TYPE_SIZE);
	stCardType[1] = '\0';
         		/* convert stCardType to int */
	inTranCardType = *stCardType - '0';
	if((inTranCardType == STANDALONE_CARD) ||(inTranCardType == VEHICLE_CARD)||(inTranCardType == DRIVER_CARD))
		inShellPrintProductLines(&obPrinter , pobTran);
#endif /* SHELL_FLEET */

if(pobTran->srTRTRec.TransactionCode != CITI_EPP_SALE && pobTran->srBRec.inCode != CITI_EPP_SALE  &&
	pobTran->srTRTRec.TransactionCode !=CITI_EPP_CASHBACK && pobTran->srBRec.inCode != CITI_EPP_CASHBACK &&
	pobTran->srTRTRec.TransactionCode !=CITI_EPP_CASH && pobTran->srBRec.inCode != CITI_EPP_CASH)
   	    if (inCITIPrintReceiptBottomLines( &obPrinter, pobTran ))
       	    return(VS_ERR);

if((pobTran->srTRTRec.TransactionCode == CITI_EPP_SALE) || (pobTran->srBRec.inCode == CITI_EPP_SALE ))
	   if(inCITIEPPReceiptBottomLines(&obPrinter,pobTran))
	   	    return(VS_SUCCESS);
if((pobTran->srTRTRec.TransactionCode == CITI_EPP_CASHBACK) || (pobTran->srBRec.inCode == CITI_EPP_CASHBACK ))
	   if(inCITIEPPCASHBACKReceiptBottomLines(&obPrinter,pobTran))
	   	    return(VS_SUCCESS);
if((pobTran->srTRTRec.TransactionCode == CITI_EPP_CASH) || (pobTran->srBRec.inCode == CITI_EPP_CASH))
	   if(inCITIEPPCASHReceiptBottomLines(&obPrinter,pobTran))
	   	    return(VS_SUCCESS);
 /* CPAC LENIN #if TBD_CPAC */
        vdSetReceiptFooterConditions(pobTran);
/* CPAC LENIN #endif  TBD_CPAC */
/* CPAC LENIN #if TBD_CPAC */

if (inPrintReceiptFooterLines( &obPrinter))
            return(VS_ERR);
/* CPAC LENIN #endif  TBD_CPAC */


#if CPAC_REP_DEBUG

        if ( (hReprint = open(REPRINT_FILE_NAME, O_CREAT|O_TRUNC|O_RDWR)) < 0 )
            return(VS_ERR);

       	if ( write(hReprint, (char *)&pobTran->srBKey.lnInvNum, sizeof (long) ) != sizeof (long) )
            return(VS_ERR);

        close(hReprint);

#endif /* CPAC_REP_DEBUG */

/* Added for new Reprint Functionality */

      /*  if ( db_open(&dbReprintFile, REPRINT_FILE_NAME, SIZE_BATCH_KEY, (O_TRUNC | O_CREAT | O_RDWR)) < 0 )
        {
            return(VS_ERR);
        }

        if ( inWriteBatchData (&dbReprintFile, &pobTran->srBKey, &pobTran->srBRec, DB_APPEND) != VS_SUCCESS )
        {
            vdSGErrorMessage(BATCH_ERR_MSG);
            return(VS_ERR);
        }

        if ( inCloseBatch(&dbReprintFile) != VS_SUCCESS)
        {
            vdSGErrorMessage(BATCH_ERR_MSG);
        }*/


    	pobTran->fPreprinted = VS_FALSE;

    	return(VS_SUCCESS);
}


int inCITIPrintReceiptBottomLines(PRINTER_OBJECT *obPrinter, TRANSACTION_OBJECT *pobTran)
	{/* changed NOSIGN_LINE to BOTTOM_END */
	long lnAmountCondition	;



	lnAmountCondition = 0L;

	if ((pobTran->fAdjust==VS_TRUE) && (pobTran->fTipAdjust == VS_TRUE)) {
		lnAmountCondition=0x0L;
		if (pobTran->srBRec.fTipEntered== VS_TRUE)  {
				if (pobTran->srBRec.lnTipAmount==0L)
					lnAmountCondition|=0x2L;
				else
					lnAmountCondition|=0x8L;

			}

		lnAmountCondition|=0x200L;
		lnAmountCondition|=0x40000L;
		lnAmountCondition|=0x400000L;

	}
	else if ((pobTran->fAdjust==VS_TRUE) && (pobTran->srBRec.fTipEntered == VS_TRUE)) {
		lnAmountCondition=0x0L;
		if (pobTran->srBRec.fTipEntered== VS_TRUE)  {
				if (pobTran->srBRec.lnTipAmount==0L)
					lnAmountCondition|=0x2L;
				else
					lnAmountCondition|=0x8L;

			}

		lnAmountCondition|=0x200L;
		lnAmountCondition|=0x40000L;
		lnAmountCondition|=0x400000L;

	}
	else if(pobTran->fAdjust==VS_TRUE)
	{
		lnAmountCondition=0x0L;
		lnAmountCondition|=0x10000L;
		lnAmountCondition|=0x400000L;
		if (pobTran->srBRec.lnTipAmount!=0L)
					lnAmountCondition|=0x8L;
	}
	else if (pobTran->fTipAdjust == VS_TRUE) {
			lnAmountCondition = 0L;
			if (pobTran->srBRec.fTipEntered== VS_TRUE)  {
				if (pobTran->srBRec.lnTipAmount==0L)
					lnAmountCondition|=0x2L;
				else
					lnAmountCondition|=0x8L;

			}
			lnAmountCondition|=0x200000L;
			//lnAmountCondition|=0x8L;
			if (pobTran->srBRec.lnTipAmount!=0L)
			lnAmountCondition|=0x40000L;
	}
	else if (pobTran->srBRec.fTipEntered== VS_TRUE)  {
				lnAmountCondition=0;
				if (pobTran->srBRec.lnTipAmount==0L)
					lnAmountCondition|=0x2L;
				else {
					lnAmountCondition|=0x8L;
					lnAmountCondition|=0x40000L;
				}

			lnAmountCondition|=0x200000L;
			//lnAmountCondition|=0x8L;

}
	if ((pobTran->srBKey.fVoided && (pobTran->srBRec.inCode != REFUND && pobTran->srBRec.inCode != REFUND_OFFLINE && pobTran->srBRec.inCode != REFUND_DEBIT)) || 
		(pobTran->srTRTRec.TransactionCode == REFUND) || 
		(pobTran->srTRTRec.TransactionCode == REFUND_OFFLINE) ||
		(pobTran->srTRTRec.TransactionCode == IMAM_PREAUTH_CANCEL)) {//: add '-' sign;
		memmove(&srRcpt.unFrm.srReceipt.szBaseAmt[1], srRcpt.unFrm.srReceipt.szBaseAmt, sizeof(srRcpt.unFrm.srReceipt.szBaseAmt)-2);
		srRcpt.unFrm.srReceipt.szBaseAmt[0] = '-';
		memmove(&srRcpt.unFrm.srReceipt.szTipAmt[1], srRcpt.unFrm.srReceipt.szTipAmt, sizeof(srRcpt.unFrm.srReceipt.szTipAmt)-2);
		srRcpt.unFrm.srReceipt.szTipAmt[0] = '-';
		memmove(&srRcpt.unFrm.srReceipt.szTotAmt[1], srRcpt.unFrm.srReceipt.szTotAmt, sizeof(srRcpt.unFrm.srReceipt.szTotAmt)-2);
		srRcpt.unFrm.srReceipt.szTotAmt[0] = '-';
		if (pobTran->srBRec.inPlan>=4 && pobTran->srBRec.inInstallments>=1) {//ONLINE REDEMPT
			memmove(&srRcpt.unFrm.srReceipt.szGenBuf5[1], srRcpt.unFrm.srReceipt.szGenBuf5, sizeof(srRcpt.unFrm.srReceipt.szGenBuf5)-2);
			srRcpt.unFrm.srReceipt.szGenBuf5[0] = '-';
			memmove(&srRcpt.unFrm.srReceipt.szGenBuf3[1], srRcpt.unFrm.srReceipt.szGenBuf3, sizeof(srRcpt.unFrm.srReceipt.szGenBuf3)-2);
			srRcpt.unFrm.srReceipt.szGenBuf3[0] = '-';			
		}//end of add
		if ((pobTran->fAdjust == VS_TRUE) || (pobTran->fTipAdjust == VS_TRUE))
			lnAmountCondition |= 0x40000L;
		else
			lnAmountCondition |= 0x80000L;
	}

#ifdef HKGM //Kelvin_F2 --- start: display a blank line of TIP when tip mode turn on.
	else if (inGetTipProcessing() > TIP_OFF){
			lnAmountCondition|=0x200000L;
			lnAmountCondition|=0x2L;
	}
#endif //Kelvin_F2 --- end: display a blank line of TIP when tip mode turn on.
#ifdef CITI //Bug fix for CITI tip line printing....
	else if (inGetTipProcessing() > TIP_OFF){
			lnAmountCondition|=0x200000L;
			lnAmountCondition|=0x2L;
	}
#endif
	//spqalog
	if ((pobTran->srBRec.inCode == REFUND) ||
		(pobTran->srBRec.inCode == REFUND_OFFLINE) ||
		(pobTran->srBRec.inCode == AUTH_ONLY) ||
		(pobTran->srBRec.inCode == IMAM_CARDVER) ||
		(pobTran->srBRec.inCode == PRE_AUTH)){
			lnAmountCondition= 0L;

	}
//if (pobTran->srBRec.fTipEntered== VS_TRUE)

	{ //LIEM add for SSP and AIRLINE
		if (pobTran->srBRec.inPlan>=1 && pobTran->srBRec.inPlan<=3 && pobTran->srBRec.inInstallments>=2) {
			lnAmountCondition |= 0x20000000L;
		}
		if (pobTran->srBRec.inPlan>=4 && pobTran->srBRec.inInstallments>=1) {
			lnAmountCondition |= 0x40000000L;
		}
		if ((fGetImamAirlineTrx()) && (strlen(pobTran->srBRec.szCustNum))) { 
			lnAmountCondition |= 0x2000000L;
		}
		if ((fGetImamPrivateLabel()) && (strlen(pobTran->srBRec.szCustNum))) { 
			lnAmountCondition |= 0x1000000L;
		}
		if (pobTran->srTRTRec.TransactionCode == DEBIT_BAL_INQ) {
			lnAmountCondition |= 0x00100000L;
		}
		if (pobTran->srTRTRec.TransactionCode == POINT_BAL_INQ) {
			srRcpt.unFrm.srReceipt.szTotAmt[0] = ' ';
			srRcpt.unFrm.srReceipt.szTotAmt[1] = ' ';
			lnAmountCondition |= 0x00800000L;
		}
	}

  if (inPrintLines(obPrinter, AMOUNT_START, AMOUNT_END, NO_BL_LINE, lnAmountCondition) != VS_SUCCESS)
        return(VS_ERR);

	{// Add for BNI style printing
		lnMiddleCondition = 0L;
		lnMiddleCondition |= 0x00010000L; //ADD SPACE BETWEEN SIGN

		if (pobTran->srBRec.inChipStatus==EMV_CARD){
			char szCVM[20];
			memset(szCVM, 0x00,sizeof(szCVM));
			inGetBatchFieldData(&pobTran->srBRec, CITI_EMV_CVM_RESULTS, (unsigned char *)szCVM, 6);
			if ((strcmp(&szCVM[1], "10302") == 0) || //PLAIN OFFLINE PIN
				(strcmp(&szCVM[1], "20302") == 0) || //ONLINE PIN
				(strcmp(&szCVM[1], "40302") == 0)	 //ENC OFFLINE PIN
				){  //No SIGN of because CVM
				lnMiddleCondition = 0L;
				lnMiddleCondition |= 0x00100000L;
			}
		}
		if (pobTran->srBRec.inChipStatus == IMAM_CHIP_TAP_CARD){
			unsigned char szCTLCVMLimit[13];
			unsigned long ulCTLCVMLimit = 0L; 
			memset(szCTLCVMLimit, 0x00, sizeof(szCTLCVMLimit));
			strcpy((char *)szCTLCVMLimit, szGetImamCTLDF01_CvmLimit());
			if (strlen((char *)szCTLCVMLimit)>2) szCTLCVMLimit[strlen((char *)szCTLCVMLimit)-2] = 0x00;
			ulCTLCVMLimit = atol((char *)szCTLCVMLimit);
			if ((pobTran->srBKey.lnTotalOfTransactionAmount <= ulCTLCVMLimit) && (ulCTLCVMLimit > 0L)){
				lnMiddleCondition = 0L;
				lnMiddleCondition |= 0x00100000L;  //UNDER CVM LIMIT
			}
		}
		if (pobTran->srBRec.inChipStatus == IMAM_MSD_TAP_CARD){
			unsigned char szCTLFloorLimit[13];
			unsigned long ulCTLFloorLimit = 0L; 
			memset(szCTLFloorLimit, 0x00, sizeof(szCTLFloorLimit));
			strcpy((char *)szCTLFloorLimit, szGetImamCTLDF02_FloorLimit());
			if (strlen((char *)szCTLFloorLimit)>2) szCTLFloorLimit[strlen((char *)szCTLFloorLimit)-2] = 0x00;
			ulCTLFloorLimit = atol((char *)szCTLFloorLimit);
			if ((pobTran->srBKey.lnTotalOfTransactionAmount <= ulCTLFloorLimit) && (ulCTLFloorLimit > 0L)){
				lnMiddleCondition = 0L;
				lnMiddleCondition |= 0x00100000L;  //MSD UNDER FLOOR LIMIT
			}
		}
		if (pobTran->srBRec.inTranCardType == DEBIT_CARD){ //PIN BASED DEBIT NO SIGNATURE
			lnMiddleCondition = 0L;
			lnMiddleCondition |= 0x00100000L;
		} 

		if (pobTran->srTRTRec.TransactionCode == DEBIT_BAL_INQ) { //
			lnMiddleCondition = 0L;
			lnMiddleCondition |= 0x00800000L;
			lnBottomCondition |= 0x00800000L;
		}
		if (pobTran->srTRTRec.TransactionCode == POINT_BAL_INQ) {
			lnMiddleCondition = 0L;
			lnMiddleCondition |= 0x00800000L;
			lnBottomCondition |= 0x00800000L;
		}

		if (pobTran->srBRec.inPrintOption == PRT_CUST)
  			lnMiddleCondition |= 0x10000000L;
		else if (pobTran->srBRec.inPrintOption == PRT_BANK)
  			lnMiddleCondition |= 0x20000000L;
		else
			lnMiddleCondition |= 0x40000000L;
	}

  /* To print more lines for Signature */
	//if (inPrintLines(obPrinter, 105, 107, NO_BL_LINE, 0L) != VS_SUCCESS)
    //    return(VS_ERR);

  if (inPrintLines(obPrinter, CPAC_SIGN_LINE_START, CPAC_SIGN_LINE_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
        return(VS_ERR);/* LENIN CPAC */
 //  lnBottomCondition=0L;
 /*  if (uinCurrentState==CITI_PFR_BEGIN_CUST_PRINTING_RECEIPT)
  	lnBottomCondition=0x10000000L;
  else if (uinCurrentState==CITI_PFR_BEGIN_BANK_PRINTING_RECEIPT)
  	lnBottomCondition=0x20000000L; */
 if (inPrintLines(obPrinter, CPAC_BOTTOM_START, CPAC_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
        return(VS_ERR);/* LENIN CPAC */
    return(VS_SUCCESS);
}


int inCITIEPPReceiptBottomLines(PRINTER_OBJECT *obPrinter, TRANSACTION_OBJECT *pobTran)
{/* changed NOSIGN_LINE to BOTTOM_END */
  char szMyScratch1[15+1];
  char szMyScratch2[13+1];
  char szMyScratch3[20+1];
  int inEPPReturn;
  long balanceAmount;
  int months;
  char szMonth1[3+1];
  char szMonth2[3+1];
  memset(szMonth1, 0x00,sizeof(szMonth1));
  memset(szMonth2, 0x00, sizeof(szMonth2));
  memset(szMyScratch1,0x00, sizeof(szMyScratch1));
  memset(szMyScratch2,0x00, sizeof(szMyScratch2));
  memset(szMyScratch3,0x00, sizeof(szMyScratch3));
  inGetBatchFieldData(&pobTran->srBRec, CITI_EPP_TENOR, (unsigned char *)szMyScratch1, 5);
  inGetBatchFieldData(&pobTran->srBRec, CITI_EPP_MONTHLY_DUE, (unsigned char *)szMyScratch2, 13);
  //memcpy(srRcpt.unFrm.srReceipt.szGenBuf2, &(szMyScratch1[2]), 3);
  memcpy(szMonth1, &(szMyScratch1[2]), 3);
  months = atoi(szMonth1);
  sprintf(szMonth2,"%d",months);
  strcpy(srRcpt.unFrm.srReceipt.szGenBuf2,szMonth2);
  //memcpy(srRcpt.unFrm.srReceipt.szGenBuf2, &(szMyScratch1[2]), 3);
  //strcpy(srRcpt.unFrm.srReceipt.szGenBuf3, "0000000003456");
  memset(srRcpt.unFrm.srReceipt.szGenBuf3, 0x00,sizeof(srRcpt.unFrm.srReceipt.szGenBuf3));///ivan
  balanceAmount = atol(szMyScratch2);
  sprintf(srRcpt.unFrm.srReceipt.szGenBuf3, "%ld", balanceAmount);
  //strcpy(srRcpt.unFrm.srReceipt.szGenBuf3, szMyScratch2);

  //memcpy(srRcpt.unFrm.srReceipt.szGenBuf3, &(szMyScratch2[0]), 13);
   vdFormatAmount(srRcpt.unFrm.srReceipt.szGenBuf3, VS_TRUE);
 //strcpy( srRcpt.unFrm.srReceipt.szGenBuf2, (char*)srISO.pszField62);
 inEPPReturn = inEPPMonthCalculation(pobTran);
  inGetBatchFieldData(&pobTran->srBRec, CITI_EPP_1STMONTH_PAY,(unsigned char *)szMyScratch3, inEPPReturn);
memset(srRcpt.unFrm.srReceipt.szGenBuf4, 0x00,sizeof(srRcpt.unFrm.srReceipt.szGenBuf4));///ivan
  memcpy(srRcpt.unFrm.srReceipt.szGenBuf4, &(szMyScratch3[0]), inEPPReturn);
 vdFormatAmount(srRcpt.unFrm.srReceipt.szGenBuf4, VS_TRUE);

  if (inPrintLines(obPrinter, 122, 126, NO_BL_LINE, 0L) != VS_SUCCESS)
		return(VS_ERR);
  if (inPrintLines(obPrinter, 105, 106, NO_BL_LINE, 0L) != VS_SUCCESS)
	  return(VS_ERR);

	if (inPrintLines(obPrinter, CPAC_SIGN_LINE_START, 67, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
		  return(VS_ERR);/* LENIN CPAC */
	 if (inPrintLines(obPrinter, 127, 129, NO_BL_LINE, 0L) != VS_SUCCESS)
	  return(VS_ERR);
   //  lnBottomCondition=0L;
   /*  if (uinCurrentState==CITI_PFR_BEGIN_CUST_PRINTING_RECEIPT)
	  lnBottomCondition=0x10000000L;
	else if (uinCurrentState==CITI_PFR_BEGIN_BANK_PRINTING_RECEIPT)
	  lnBottomCondition=0x20000000L; */
   if (inPrintLines(obPrinter, CPAC_BOTTOM_START, CPAC_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
		  return(VS_ERR);/* LENIN CPAC */

	// Frederick_L1 08122004, Changes as per Sheryl Chan of Citibank's Request to add messages for EPP transactions
	// START Frederick_L1, Added as per Sheryl Chan of Citibank request. this is to print special footer message for EPP only
	if (fGetPrintEPPFooter() == VS_TRUE)
	{
		long lnFooterCondition;

		lnFooterCondition = 0L;
		if (inPrintLines(obPrinter, 102, 102, NO_BL_LINE, lnFooterCondition) != VS_SUCCESS)
			return(VS_ERR);
		lnFooterCondition = 128L;
		if (inPrintLines(obPrinter, CITI_EPP_FOOTER_START, CITI_EPP_FOOTER_END, NO_BL_LINE, lnFooterCondition) != VS_SUCCESS)
			return(VS_ERR);/* LENIN CPAC */
		lnFooterCondition = 0L;
		if (inPrintLines(obPrinter, 102, 102, NO_BL_LINE, lnFooterCondition) != VS_SUCCESS)
			return(VS_ERR);

	}

return(VS_SUCCESS);
}

int inCITIEPPCASHBACKReceiptBottomLines(PRINTER_OBJECT *obPrinter, TRANSACTION_OBJECT *pobTran)
{

char szBuffer[15+1];
memset(szBuffer,0x00,sizeof(szBuffer));
   sprintf(srRcpt.unFrm.srReceipt.szGenBuf6,"%ld", pobTran->srBRec.lnBaseTransactionAmount);
   vdFormatAmount(srRcpt.unFrm.srReceipt.szGenBuf6, VS_TRUE);
    if (inPrintLines(obPrinter, 130, 130, NO_BL_LINE, 0L) != VS_SUCCESS)
		return(VS_ERR);
  if (inPrintLines(obPrinter, 105, 106, NO_BL_LINE, 0L) != VS_SUCCESS)
	  return(VS_ERR);

	if (inPrintLines(obPrinter, CPAC_SIGN_LINE_START, 67, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
		  return(VS_ERR);/* LENIN CPAC */
	 if (inPrintLines(obPrinter, 131, 133, NO_BL_LINE, 0L) != VS_SUCCESS)
	  return(VS_ERR);
   //  lnBottomCondition=0L;
   /*  if (uinCurrentState==CITI_PFR_BEGIN_CUST_PRINTING_RECEIPT)
	  lnBottomCondition=0x10000000L;
	else if (uinCurrentState==CITI_PFR_BEGIN_BANK_PRINTING_RECEIPT)
	  lnBottomCondition=0x20000000L; */
   if (inPrintLines(obPrinter, CPAC_BOTTOM_START, CPAC_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
		  return(VS_ERR);/* LENIN CPAC */

return(VS_SUCCESS);
}

int inCITIEPPCASHReceiptBottomLines(PRINTER_OBJECT *obPrinter, TRANSACTION_OBJECT *pobTran)
{

  if (inPrintLines(obPrinter, 134, 137, NO_BL_LINE, 0L) != VS_SUCCESS)
		return(VS_ERR);
  if (inPrintLines(obPrinter, 105, 106, NO_BL_LINE, 0L) != VS_SUCCESS)
	  return(VS_ERR);

	if (inPrintLines(obPrinter, CPAC_SIGN_LINE_START, 67, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
		  return(VS_ERR);/* LENIN CPAC */
	 if (inPrintLines(obPrinter, 131, 133, NO_BL_LINE, 0L) != VS_SUCCESS)
	  return(VS_ERR);
   //  lnBottomCondition=0L;
   /*  if (uinCurrentState==CITI_PFR_BEGIN_CUST_PRINTING_RECEIPT)
	  lnBottomCondition=0x10000000L;
	else if (uinCurrentState==CITI_PFR_BEGIN_BANK_PRINTING_RECEIPT)
	  lnBottomCondition=0x20000000L; */
   if (inPrintLines(obPrinter, CPAC_BOTTOM_START, CPAC_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
		  return(VS_ERR);/* LENIN CPAC */

return(VS_SUCCESS);
}

int inEPPMonthCalculation(TRANSACTION_OBJECT *pobTran)
{
   char szMyScratch1[15+1];
   char szMyScratch2[13+1];
   char szMyScratch3[3+1];
   char szMyScratch4[20+1];
 long inSubMonthPay;
 long inTotalMonths;
 long inEPPTotalAmount;
 long in1stMonthPay;
 long in1stMonthPay1;
   memset(szMyScratch1,0x00, sizeof(szMyScratch1));
   memset(szMyScratch2,0x00, sizeof(szMyScratch2));
   memset(szMyScratch3,0x00, sizeof(szMyScratch3));
   memset(szMyScratch4,0x00, sizeof(szMyScratch4));
   inGetBatchFieldData(&pobTran->srBRec, CITI_EPP_MONTHLY_DUE, (unsigned char *)szMyScratch2, 13);
   inGetBatchFieldData(&pobTran->srBRec, CITI_EPP_TENOR, (unsigned char *)szMyScratch1, 5);
   inSubMonthPay = atol(szMyScratch2);
   memcpy(szMyScratch3, &(szMyScratch1[2]), 3);
   //sprintf(inEPPTotalAmount, "%s", szMyScratch3);
   inTotalMonths = atol(szMyScratch3);
    inEPPTotalAmount = inTotalMonths * inSubMonthPay;
   in1stMonthPay = pobTran->srBRec.lnBaseTransactionAmount - inEPPTotalAmount;
   in1stMonthPay1 = in1stMonthPay + inSubMonthPay;
   sprintf(szMyScratch4,"%ld", in1stMonthPay1);
  LOG_PRINTFF((0x8L,"EESL_Send return Value:%ld",inEPPTotalAmount));
   inStoreBatchFieldData(&pobTran->srBRec, CITI_EPP_1STMONTH_PAY, (unsigned char *)szMyScratch4, strlen(szMyScratch4));
   return(strlen(szMyScratch4));

}



int inCITIPrinterCheck(TRANSACTION_OBJECT *pobTran)
{
    if (!pobTran->fPreprinted)
    {
        if (inCITIChkPrinterStatus(&obPrinter) != VS_SUCCESS)
        {
            vdSetPrintReceipt(pobTran, VS_FALSE);
            return(VS_ERR);
        }
    }
    return(VS_SUCCESS);
}


int inCITIChkPrinterStatus(PRINTER_OBJECT* pobPrinter) {
    int inResult;
    int inPriorStatus = YES;

    //pdebug(("--inChkPrinterStatus--"));

    /*
     *      Printer is NOT available or NOT Enabled.
     */
    if (inGetPrinterType() == NOPRINTER)// || fGetEnablePrinter() == NO)
        return(VS_SUCCESS);

    /*
     *      Check the Printer Status
     */
    inResult = pobPrinter->shStatus(pobPrinter->inHandle, PRINTER_TIME_OUT);
    //pdebug(("  Stat=%d", inResult));
    switch (inResult) {
    case PAPER_OUT:
	do{
		vdDisplayWarningString("Out of paper!!");
		vdDelay(500);
		vdDisplayWarningString("press a key to print");
		vdDelay(1000);
		if(KBHIT()) break;
	}while(1);//get_char();


	 // inPriorStatus = fGetEnablePrinter();
        //    INCREMENT_PRINTER_ERROR;
        //inResult = VS_ERR;
        /* vdSetPCTEnablePrinter(NO); */
	//   break;
    case OK:
    case PAPER_LOW:
        //vdSetPCTEnablePrinter(YES);
        inPriorStatus = NO;
        inResult = VS_SUCCESS;
        break;
    default:
        /*
        *      Attempt to re-open the Printer, this will set printer to NO_PRINTER on failure.
        */
        LOG_PRINTF(("Stat=%d,errno=%d", inResult, errno));
        close(pobPrinter->inHandle);
        inResult = inOpenPrinter();
        if (inResult == OK)
            inPriorStatus = NO;
        break;
    }

    if (inPriorStatus) {

        vdDisplayMessageFromFile(PRINTER_ERR_MSG21, WARNING_MSG);
        /* Already done above - mdm - 07/21/00 */
        /* INCREMENT_PRINTER_ERROR; */
    }


    return (inResult);
}

/*-------------------------------------------------------------------------
    Function :    inCITIGetInvoiceNumber
    Description : This function checks if there is transaction record
                  corresponding to an invoice number exists in the Batch.
                  Called in the VOID/ADJUST transaction flow.
    Parameters :
    Returns :
    Notes :
--------------------------------------------------------------------------*/

int inCITIGetInvoiceNumber (TRANSACTION_OBJECT *pobTran)///ivan
{
    char szInvoiceNumber [INV_NUM_SIZE + 1];
    int  inResult;
    int  inRowLim = inGetRowLim();

	if(pobTran->srTRTRec.TransactionCode == CITI_EPP_SALE)
	{
		delline();
       	printf("EPP SALE");
	}

	inResult = inEnterWithMessage(INVOICE_MSG, SCROLL_DISPLAY_FALSE, szInvoiceNumber,
			INPUT_NUMS, inGetInvNumSize(), inValInvoiceEntry);

	window(obDisp.inHomeCol, obDisp.inTitleLine, inRowLim, obDisp.inCharsPerColumn);

if (inResult == VS_ESCAPE)
	{
		return (VS_ESCAPE);
	}

	if (inResult < 0)
{
		return (VS_ERR);
	}

	pobTran->srBKey.lnInvNum = atol(szInvoiceNumber);

   return (VS_SUCCESS);
}


/*---------------------------------------------------------------------------
    Function :    inCITIGetInvNum()
    Description : This function obtains the invoice number from the user if
                  the key invoice flag is on.
    Parameters :
    Returns :     VS_ERR or VS_SUCCESS
    Notes :
 ---------------------------------------------------------------------------*/

int inCITIGetInvNum(TRANSACTION_OBJECT* pobTran) {
    char szInvoiceNumber[INV_NUM_SIZE + 1];
    int inResult;

    int inRowLim = inGetRowLim();

    inResult = VS_ERR;


#if CPAC_REMOVED

    if (fGetKeyInvNum() == VS_FALSE)
        return(VS_SUCCESS);

#endif /* CPAC_REMOVED */
    /*
    #ifdef CITI_IND
        inResult = inCheckForDuplicate(pobTran);
        if (inResult == VS_SUCCESS) return (VS_ERR);
    #endif*/

    if (fGetKeyInvNum() == VS_FALSE) {
        /*
         *      if the transaction is a Close Tab and Offline (which means the card
         *      number is the same as the Open Tab) then use the invoice number in the batch record
         */
        if (!pobTran->srBRec.fCloseTabSameCard)
        {
               pobTran->srBKey.lnInvNum = lnGetInvNum();///ivan
		while(TRUE)
		{
                         inResult = inCheckForDuplicate(pobTran);

		 	if (inResult != VS_SUCCESS)
		 	{
                		break;
		 	}
			else
			{
                   		(pobTran->srBKey.lnInvNum)++;
			}
		}
        }


        return(VS_SUCCESS);
    }


    /* If the transaction is Close Tab and card number is the same as the
     * Open Tab, exit.
     * Else if the card number is different (it was changed to online) there
     * needs to be a new invoice number.
     */
    if (pobTran->srBRec.fCloseTabSameCard)
        return(VS_SUCCESS);

    while (TRUE) {
        if (inResult == VS_SUCCESS) {
            vdDisplayMessageFromFile(DUPLICATE_INV_NUM_MSG, STATUS_MSG);
            SVC_WAIT(2000);
        }
        szInvoiceNumber[0] = '\0';

#if VIP_RMD
        inResult = inEnterWithMessage(INVOICE_MSG, SCROLL_DISPLAY_TRUE, szInvoiceNumber, INPUT_NUMS, inGetInvNumSize(), inValidateString);
#endif /* VIP_RMD */

        if (getgrid() == 0)
            inResult = inCPACEnterWithMessage(INVOICE_MSG, SCROLL_DISPLAY_TRUE, 3, 6, szInvoiceNumber, INPUT_NUMS, inGetInvNumSize(), inValidateString);
        else
            inResult = inCPACEnterWithMessage(INVOICE_MSG, SCROLL_DISPLAY_TRUE, 5, 5, szInvoiceNumber, INPUT_NUMS, inGetInvNumSize(), inValidateString);


        window(obDisp.inHomeCol, obDisp.inTitleLine, inRowLim, obDisp.inCharsPerColumn);

        if (gu_clr_state())
            return(VS_ESCAPE);

        if (inResult < 0) {
            vdSGErrorMessage(TXN_CANCELLED);
            return (inResult);
        }

        if (atol(szInvoiceNumber) == 0L) {
            vdDisplayMessageFromFile(INVALID_INV_NUM_ERR_MSG, STATUS_MSG);
            SVC_WAIT(2000);
            inResult = VS_ERR;
            continue;
        }

        /* Search in the Open Tab Batch for same Invoice Number and Host Type */
        /* Search in the Host Batch for same Invoice Number */
        pobTran->srBKey.lnInvNum = atol(szInvoiceNumber);

        //#ifndef CITI_IND
#ifdef BATCH_DEFINED
        inResult = inCheckForDuplicate(pobTran);
#endif // BATCH_DEFINED
        //#endif

        if (inResult != VS_SUCCESS)
            break;
    }

    vdSetInvNum(pobTran->srBKey.lnInvNum);

    vdSGErrorMessage(0L);

    return(VS_SUCCESS);
}


int inCITIRePrintSettleReport(PRINTER_OBJECT* pobPrinter,TRANSACTION_OBJECT* pobTran) {
    char szFileName[FILENAME_SIZE + 1];
    int inNoOfRecs,
    inRecCnt = 1,
    Count,
    inNoBytes;
    int Grand = 0;
    long lnHeaderCond,
    lnMiddleCond,
    lnBottomCond;

    /*  Printing Settlement Header */


    vdGetReprintSettleFileName(szFileName, CPAC_HEADER);

    if (inDBFileExists(szFileName) != VS_SUCCESS) {
        vdDisplayErrorMessage(REC_NOT_FOUND_ERR_MSG);
        return(VS_ERR);
    }

    inPrintReceiptHeader(pobTran);


    inNoBytes = inDBReadRecord(szFileName, 1, (unsigned char *) &srCPACSettleHeader);
    if (inNoBytes < 0)
        return (VS_ERR);

    strcpy(srRcpt.szDate, srCPACSettleHeader.szDate);
    strcpy(srRcpt.szTime, srCPACSettleHeader.szTime);
    strcpy(srRcpt.szMerchantId, srCPACSettleHeader.szMID);
    strcpy(srRcpt.szTermId, srCPACSettleHeader.szTID);
    strcpy(srRcpt.szBatchNum, srCPACSettleHeader.szBatchNum);
    strcpy(srRcpt.szHostName, srCPACSettleHeader.szHostName);
    lnHeaderCond = srCPACSettleHeader.lnHeaderCond;
    lnHeaderCond |= 0x10000000L; //Kelvin_f2 make it print "DUPLICATE" line

#ifdef AMEX_SOC
    strcpy(srRcpt.unFrm.srReceipt.szGenBuf2, srCPACSettleHeader.szSOC);
#endif   /*  AMEX_SOC */

    if (inPrintLines(pobPrinter, CPAC_SUMMARY_TOP_START, CPAC_SUMMARY_TOP_END, NO_BL_LINE, lnHeaderCond) != VS_SUCCESS)
        return(VS_ERR);

#ifdef AMEX_SOC
    if (strcmp(szGetHostFileName(), "AXAP") == 0) {
        if (inPrintLines(&obPrinter, AMEX_SOC_PRINT_START, AMEX_SOC_PRINT_END, NO_BL_LINE, 4L) != VS_SUCCESS)
            return(VS_ERR);
    } else {
        // If it is not AXAP, depend on condition line set in TPL file.
        if (inPrintLines(&obPrinter, AMEX_SOC_PRINT_START, AMEX_SOC_PRINT_END, NO_BL_LINE, 2L) != VS_SUCCESS)
            return(VS_ERR);
    }

#endif /*   AMEX_SOC */


    /* Printing the Body of the Settlement Report */

    vdGetReprintSettleFileName(szFileName, CPAC_BODY);

    if (inDBFileExists(szFileName) != VS_SUCCESS) {
        vdDisplayErrorMessage(REC_NOT_FOUND_ERR_MSG);
        return(VS_ERR);
    }

    inNoOfRecs = inDBTotalRecords(szFileName);

    if (inNoOfRecs == 1) {
        inNoBytes = inDBReadRecord(szFileName, inNoOfRecs, (unsigned char *) &srCPACSettleMiddle);
        if (inNoBytes < 0)
            return (VS_ERR);

        strcpy(srRcpt.unFrm.srSummary.srMid.szCType, srCPACSettleMiddle.szCardName);
        strcpy(srRcpt.unFrm.srSummary.srMid.szCreditCount, srCPACSettleMiddle.szCreditCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szCreditTotal, srCPACSettleMiddle.szCreditTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szDebitCount, srCPACSettleMiddle.szDebitCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szDebitTotal, srCPACSettleMiddle.szDebitTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szShiftNumber, srCPACSettleMiddle.szShiftNum);
	 strcpy(srRcpt.unFrm.srSummary.srMid.szEPPSaleCount, srCPACSettleMiddle.szShiftEPPSale);
        strcpy(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, srCPACSettleMiddle.szSurCharge);
        strcpy(srRcpt.unFrm.srSummary.srMid.szAdjustCount, srCPACSettleMiddle.szAdjCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, srCPACSettleMiddle.szAdjTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szReversalCount, srCPACSettleMiddle.szReversalCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szReversalTotal, srCPACSettleMiddle.szReversalTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szNetCount, srCPACSettleMiddle.szNetCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szNetTotal, srCPACSettleMiddle.szNetTot);
	 strcpy(srRcpt.unFrm.srSummary.srMid.szEPPSaleCount, srCPACSettleMiddle.szEPPSaleCount);
	 strcpy(srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal, srCPACSettleMiddle.szEPPSaleSurchrgeTotal);
        lnMiddleCond = srCPACSettleMiddle.lnMiddleCond;

        if (inPrintLines(pobPrinter, CPAC_SUMMARY_MIDDLE_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, lnMiddleCond) != VS_SUCCESS)
            return(VS_ERR);
    } else {
        for (Count = 1; Count < inNoOfRecs; Count++) {
            inNoBytes = inDBReadRecord(szFileName, Count, (unsigned char *) &srCPACSettleMiddle);
            if (inNoBytes < 0)
                return (VS_ERR);

            strcpy(srRcpt.unFrm.srSummary.srMid.szCType, srCPACSettleMiddle.szCardName);
            strcpy(srRcpt.unFrm.srSummary.srMid.szCreditCount, srCPACSettleMiddle.szCreditCnt);
            strcpy(srRcpt.unFrm.srSummary.srMid.szCreditTotal, srCPACSettleMiddle.szCreditTot);
            strcpy(srRcpt.unFrm.srSummary.srMid.szDebitCount, srCPACSettleMiddle.szDebitCnt);
            strcpy(srRcpt.unFrm.srSummary.srMid.szDebitTotal, srCPACSettleMiddle.szDebitTot);
            strcpy(srRcpt.unFrm.srSummary.srMid.szShiftNumber, srCPACSettleMiddle.szShiftNum);
	     strcpy(srRcpt.unFrm.srSummary.srMid.szEPPSaleCount, srCPACSettleMiddle.szShiftEPPSale);
            strcpy(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, srCPACSettleMiddle.szSurCharge);
            strcpy(srRcpt.unFrm.srSummary.srMid.szAdjustCount, srCPACSettleMiddle.szAdjCnt);
            strcpy(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, srCPACSettleMiddle.szAdjTot);
            strcpy(srRcpt.unFrm.srSummary.srMid.szReversalCount, srCPACSettleMiddle.szReversalCnt);
            strcpy(srRcpt.unFrm.srSummary.srMid.szReversalTotal, srCPACSettleMiddle.szReversalTot);
            strcpy(srRcpt.unFrm.srSummary.srMid.szNetCount, srCPACSettleMiddle.szNetCnt);
            strcpy(srRcpt.unFrm.srSummary.srMid.szNetTotal, srCPACSettleMiddle.szNetTot);
	     strcpy(srRcpt.unFrm.srSummary.srMid.szEPPSaleCount, srCPACSettleMiddle.szEPPSaleCount);
	     strcpy(srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal, srCPACSettleMiddle.szEPPSaleSurchrgeTotal);
            lnMiddleCond = srCPACSettleMiddle.lnMiddleCond;

            if (inPrintLines(pobPrinter, CPAC_SUMMARY_MIDDLE_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, lnMiddleCond) != VS_SUCCESS)
                return(VS_ERR);
        }

        /* Printing Grand Totals if any */

        inNoBytes = inDBReadRecord(szFileName, Count, (unsigned char *) &srCPACSettleMiddle);
        if (inNoBytes < 0)
            return (VS_ERR);

        strcpy(srRcpt.unFrm.srSummary.srMid.szCType, srCPACSettleMiddle.szCardName);
        strcpy(srRcpt.unFrm.srSummary.srMid.szCreditCount, srCPACSettleMiddle.szCreditCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szCreditTotal, srCPACSettleMiddle.szCreditTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szDebitCount, srCPACSettleMiddle.szDebitCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szDebitTotal, srCPACSettleMiddle.szDebitTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szShiftNumber, srCPACSettleMiddle.szShiftNum);
	 strcpy(srRcpt.unFrm.srSummary.srMid.szEPPSaleCount, srCPACSettleMiddle.szShiftEPPSale);
        strcpy(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, srCPACSettleMiddle.szSurCharge);
        strcpy(srRcpt.unFrm.srSummary.srMid.szAdjustCount, srCPACSettleMiddle.szAdjCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, srCPACSettleMiddle.szAdjTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szReversalCount, srCPACSettleMiddle.szReversalCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szReversalTotal, srCPACSettleMiddle.szReversalTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szNetCount, srCPACSettleMiddle.szNetCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szNetTotal, srCPACSettleMiddle.szNetTot);
	 strcpy(srRcpt.unFrm.srSummary.srMid.szEPPSaleCount, srCPACSettleMiddle.szEPPSaleCount);
	 strcpy(srRcpt.unFrm.srSummary.srMid.szEPPSaleSurchrgeTotal, srCPACSettleMiddle.szEPPSaleSurchrgeTotal);
        lnBottomCond = srCPACSettleMiddle.lnMiddleCond;

        if (inPrintLines(pobPrinter, CPAC_GRANT_TOTAL_LABEL_START, CPAC_GRANT_TOTAL_LABEL_END, NO_BL_LINE, lnBottomCond) != VS_SUCCESS)
            return(VS_ERR);

        if (inPrintLines(pobPrinter, CPAC_SUMMARY_BOTTOM_START, CPAC_SUMMARY_BOTTOM_END, NO_BL_LINE, lnBottomCond) != VS_SUCCESS)
            return(VS_ERR);
    }

    /*   Printing Footer Message */

    vdGetReprintSettleFileName(szFileName, CPAC_FOOTER);

    if (inDBFileExists(szFileName) != VS_SUCCESS) {
        vdDisplayErrorMessage(REC_NOT_FOUND_ERR_MSG);
        return(VS_ERR);
    }

    inNoBytes = inDBReadRecord(szFileName, 1, (unsigned char *) &srCPACSettleBottom);
    if (inNoBytes < 0)
        return (VS_ERR);

    lnBottomCond = srCPACSettleBottom.lnBottomCond;

    if (inPrintLines(&obPrinter, CPAC_SETTLEMENT_STATUS_START, CPAC_SETTLEMENT_STATUS_END, NO_BL_LINE, lnBottomCond) != VS_SUCCESS)
        return(VS_ERR);

    if (inPrintLines(&obPrinter, CPAC_END_OF_REPORT_START, CPAC_END_OF_REPORT_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
        return(VS_ERR);
    return (VS_SUCCESS);
}


int inCITIallReprintSettleReport(TRANSACTION_OBJECT* pobTran) {
    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }
    //if (!fGetEnablePrinter())
    //    return(VS_SUCCESS);

    inGetReport1Template();

    return(inCITIRePrintSettleReport(&obPrinter, pobTran));
}


int inCITIUpdateOfflineAccum(TRANSACTION_OBJECT* pobTran,ACCUM_VALUES* psrAccum) {
#if 0
    if (inGGCode()==SALE_OFFLINE){
        if (pobTran->srTRTRec.TransactionCode == ADJUST)
        {
            psrAccum->lnCustom2+=pobTran->srBKey.lnTotalOfTransactionAmount;
            psrAccum->lnCustom2-=pobTran->srBRec.lnOldTotalTransactionAmount;
        }
        else if (pobTran->srTRTRec.TransactionCode == VOID_SALE_OFFLINE)
        {
            psrAccum->lnCustom1-=1;
            psrAccum->lnCustom2-=pobTran->srBKey.lnTotalOfTransactionAmount;
        }
        else  {
            psrAccum->lnCustom1+=1;
            psrAccum->lnCustom2+=pobTran->srBKey.lnTotalOfTransactionAmount;
        }
    /* if (pobTran->srBKey.fVoided) {
        psrAccum->lnCustom1-=1;
        psrAccum->lnCustom2-=pobTran->srBKey.lnTotalOfTransactionAmount;
    }
     else {
        psrAccum->lnCustom1+=1;
        psrAccum->lnCustom2+=pobTran->srBKey.lnTotalOfTransactionAmount;
       }  */
    }
#endif /* 0 */
	if(pobTran->inTransactionCode == CITI_EPP_SALE) {

		psrAccum->dbCustom3+=1;
		psrAccum->dbCustom4+=pobTran->srBKey.lnTotalOfTransactionAmount;

	}

    switch (inGGCode()) {
    case SALE_OFFLINE :
        switch (pobTran->inTransactionCode) {
        case SALE_OFFLINE :
            psrAccum->dbCustom1 += 1;
            psrAccum->dbCustom2 += pobTran->srBKey.lnTotalOfTransactionAmount;
            break;
        case ADJUST      :
        case CPAC_PHIL_ADJUST:
            /* 1.4_citiphil_don_26feb_DSC_??? */
            psrAccum->dbCustom2 += pobTran->srBKey.lnTotalOfTransactionAmount;
            psrAccum->dbCustom2 -= pobTran->srBRec.lnOldTotalTransactionAmount;
            break;
        case VOID       :
            psrAccum->dbCustom1 -= 1;
            psrAccum->dbCustom2 -= pobTran->srBKey.lnTotalOfTransactionAmount;
            break;
        case TIP_ADJUST :
            psrAccum->dbCustom2 += pobTran->srBKey.lnTotalOfTransactionAmount;
            //psrAccum->lnCustom2+=pobTran->srBRec.lnTipAmount;
            //psrAccum->lnCustom2-=pobTran->srBRec.lnTipAmount;
            psrAccum->dbCustom2 -= pobTran->srBRec.lnOldTotalTransactionAmount;
            break;
        default :
            break;
        }
        /*  case ADJUST      :
                                psrAccum->lnCustom2+=pobTran->srBKey.lnTotalOfTransactionAmount;
                                psrAccum->lnCustom2-=pobTran->srBRec.lnOldTotalTransactionAmount;
                                break;
                case VOID       :
                                psrAccum->lnCustom1-=1;
                                psrAccum->lnCustom2-=pobTran->srBKey.lnTotalOfTransactionAmount;
                                break;
                case TIP_ADJUST :
                                psrAccum->lnCustom2+=pobTran->srBKey.lnTotalOfTransactionAmount;
                                psrAccum->lnCustom2-=pobTran->srBRec.lnOldTotalTransactionAmount;
                                break;*/
    default :
        break;
    }

    return(VS_SUCCESS);
}


/*---------------------------------------------------------------------------
    Function     : inCITICustComputeAndDispTotal
    Description  : Custom fn for adds all the transaction amounts and displays it on
                   the screen.
    Returns      : VS_ERR, VS_SUCCESS or VS_ESCAPE
    Globals      : srGDS.szTotalTransactionAmount
    Modification History :
      #     Date      Who                     Description
    ----- -------- ----------   ---------------------------------------------
 ---------------------------------------------------------------------------*/

int inCITICustComputeAndDispTotal(TRANSACTION_OBJECT* pobTran) {
    char szAmount[AMT_SIZE + 1];
    int inGrid;
    int inLine;
    char szDate[DATE_SIZE + 1];
    char szTime[TIME_SIZE + 1];

    inGrid = getgrid();
    if (inGrid == 0)
        inLine = 4;
    else
        inLine = inImamLineNumber-1;

    vdComputeTransactionTotal(szAmount, pobTran);
    pobTran->srBKey.lnTotalOfTransactionAmount = atol(szAmount);

    if (fGetOffline(pobTran) && !pobTran->srBRec.fCloseTabSameCard)
        pobTran->srBRec.lnOrigTotalTransactionAmount = 0L;

    if (!fGetOffline(pobTran))
        pobTran->srBRec.lnOrigTotalTransactionAmount = atol(szAmount);

    /*    if (fComputeOverage(pobTran))
            pobTran->srBRec.fComputeOverage = VS_TRUE;
        else
            pobTran->srBRec.fComputeOverage = VS_FALSE;
    */ // 1.4 sad_change_1.4

    pobTran->srBRec.fComputeOverage = (fComputeOverage(pobTran));

    if ((fGetCheckFloorLimit(pobTran) == VS_TRUE) && (fAmountLessThanFloorLimit(pobTran) == VS_TRUE)) //leo_may102K added
    {
        //Bug Fix : The Floor Lt
        inLoadTRTRec(pobTran, SALE_OFFLINE);                                                    // functionality was not working in Base!!
        vdSGCode(SALE_OFFLINE);
        vdSetOffline(pobTran, VS_TRUE);
        pobTran->inTransactionCode = SALE_OFFLINE; //1.41 label G fix
        pobTran->srBKey.fOffline = VS_TRUE;
        vdGetDate(szDate, MMDDYY);
        strcpy(pobTran->srBRec.szDate, szDate);
        vdGetTime(szTime);
        strlcpy(pobTran->srBRec.szTime, szTime, DATE_SIZE);

        if (inCheckBannedCardType(pobTran) == VS_ERR)
            return(VS_ERR);

        inInitPrintOption(pobTran);
        vdMakeFooter(pobTran);
        pobTran->srBKey.fOffline = VS_TRUE;
        pobTran->srBRec.lnMessage = SALE_OFFLINE_MSG;
    }

    sprintf(szAmount, SUBSTITUTE_LD, pobTran->srBKey.lnTotalOfTransactionAmount);
	if((pobTran->srTRTRec.TransactionCode == CITI_EPP_CASH) || (pobTran->srBRec.inCode == CITI_EPP_CASH))
		{
		  pobTran->srBKey.lnTotalOfTransactionAmount = pobTran->srBRec.lnBaseTransactionAmount+ pobTran->srBRec.lnTipAmount;
		   sprintf(szAmount, SUBSTITUTE_LD, pobTran->srBKey.lnTotalOfTransactionAmount );
		}

    vdCustScroll(); // scroll 2 lines up
    vdDispMsgAt(TOTALAMT_MSG9, 1, inLine, CLR_EOL);
    vdFormatAmount(szAmount, VS_TRUE);
    vdCustDispTotAmount(szAmount);
    if ((inGetTipPercent() > 0) && (inGetTipProcessing() > TIP_OFF))
        vdDelay(PROMPT_DELAY);
    // to meet the spec... having all the amounts on the screen

    // vdCustScroll();  //: Do we need this?  
	// scroll 2 lines up as this may be followed by the  error
    // or status messages which happens to be on the 7 th line
    // as well

    /*
    if( fGetTRTOffline() )
       {
        int inPause;
           inPause = (int)(1.25*A_SECOND);
           ulTimerCount = set_itimeout( hClock, (unsigned)inPause, (long)TM_TICKS);
           while ( !KBHIT() && CHK_TIMEOUT(hClock, ulTimerCount) ) ;
       }
    */

    return(VS_SUCCESS);
}

/*-------------------------------------------------------------------------
    Function :    vdCITIMakeReceiptTop
    Description :
    Parameters :
    Returns :
    Notes :
--------------------------------------------------------------------------*/

void vdCITIMakeReceiptTop (TRANSACTION_OBJECT *pobTran)

{
    char szExpDate[EXP_DATE_SIZE + 1];
    char  room[ROOM_NUM_SIZE + 1];
    char szTransName[MESSAGE_SIZE + 1];
    char AdjTipAdjFlag;

    char szAPPLPrefName[20+1];
    char szAPPLLabel[20+1];



    memset(srRcpt.szClerkId,'\0',sizeof(srRcpt.szClerkId));

    if(inGetClerkMode() != NO_CLERK)
        strlcpy(srRcpt.szClerkId, pobTran->srBKey.szClerkId, CLERK_ID_SIZE);

    memset(srRcpt.szTransName,'\0',sizeof(srRcpt.szTransName));

    chGetCPACAdjTipAdjflag (&pobTran->srBRec, (unsigned char *)&AdjTipAdjFlag);


    if (pobTran->srBRec.lnMessage)              /* mb1 */
        vdCPACGetMessageFromReceiptFile(pobTran->srBRec.lnMessage, szTransName,pobTran);



    if (pobTran->srBKey.fVoided == VS_TRUE)
    {
        vdCPACGetMessageFromReceiptFile(VOID_MSG6, srRcpt.szTransName,pobTran);
        pad(srRcpt.szTransName, srRcpt.szTransName, ' ', strlen(srRcpt.szTransName) + 1, LEFT);
    }
    else
    {
    	if((pobTran->inOperationCode == BATCH_REVIEW_OPERATION)||(pobTran->inTransactionCode == ADJUST)||
    		(pobTran->inTransactionCode==CPAC_PHIL_ADJUST)||(pobTran->inTransactionCode == TIP_ADJUST))

    	{
    	       //originally if(pobTran->fAdjust)
		if(pobTran->fAdjust||((AdjTipAdjFlag=='A')&&(pobTran->inTransactionCode != TIP_ADJUST)) )
			vdCPACGetMessageFromReceiptFile(ADJUST_MSG6, srRcpt.szTransName,pobTran);

		else
			//originally if(pobTran->fTipAdjust)
			if(pobTran->fTipAdjust||((AdjTipAdjFlag=='T')&&(pobTran->inTransactionCode != ADJUST)))
				vdCPACGetMessageFromReceiptFile(CPAC_TIP_ADJUST_MSG, srRcpt.szTransName,pobTran);
		pad(srRcpt.szTransName, srRcpt.szTransName, ' ', strlen(srRcpt.szTransName) + 1, LEFT);
    	}
    	else
    	{
		if (pobTran->srBRec.inNumberOfAdjusts > 0 ||
		        pobTran->srBRec.inNumberOfTipAdjusts > 0 )
		{
		       if((pobTran->srBRec.inNumberOfAdjusts > 0)&& (AdjTipAdjFlag=='A'))
		       	vdCPACGetMessageFromReceiptFile(ADJUST_MSG6, srRcpt.szTransName,pobTran);
	       	else
	       		if((pobTran->srBRec.inNumberOfTipAdjusts > 0)&& (AdjTipAdjFlag=='T'))
       			vdCPACGetMessageFromReceiptFile(CPAC_TIP_ADJUST_MSG, srRcpt.szTransName,pobTran);

		        pad(srRcpt.szTransName, srRcpt.szTransName, ' ', strlen(srRcpt.szTransName) + 1, LEFT);
    		}
    	}
    }

#ifdef ICICI
  	if((pobTran->srTRTRec.TransactionCode== CASH_ADV) || (pobTran->srBRec.inCode== CASH_ADV))
    	{
    	 	vdCPACGetMessageFromReceiptFile(CASH_ADV_TRT_MSG, srRcpt.szTransName,pobTran);
    	}
  	else
    		strcat(srRcpt.szTransName, szTransName);

	if((pobTran->srBRec.inCode== CASH_ADV) && (pobTran->srBRec.inOrgCode == VOID))
   	{
       	memset(srRcpt.szTransName,'\0', sizeof(srRcpt.szTransName));
		strcpy(srRcpt.szTransName, "VOID CASHADVANCE");
   	}

#else
	     if (inGGCode() ==CITI_EPP_SALE)///ivan
	{ 	strcpy( szTransName, "EPP SALE");
    strcat(srRcpt.szTransName, szTransName);
	 }
	 else{
    strcat(srRcpt.szTransName, szTransName);
	 	}

#endif  /* ICICI  */




    /* Pad Trans Name so that inverse print will have black symetrical */
    if ((inGetPrinterType() == PRINTER_350))
    {
//Kelvin_F2 --- start: no space in front of tranname
#ifndef HKGM
        switch ( inGetP350ColMode() )
        {
            case COLUMN_TYPE_24:
                pad(srRcpt.szTransName, srRcpt.szTransName, ' ', 12, CENTER);
                break;
            case COLUMN_TYPE_32:
                pad(srRcpt.szTransName, srRcpt.szTransName, ' ', 16, CENTER);
                break;
            case COLUMN_TYPE_42:
                pad(srRcpt.szTransName, srRcpt.szTransName, ' ', 21, CENTER);
                break;
        }
#endif /* HKGM */
//Kelvin_F2 --- end: no space in front of tranname
    }
    else{ 
        //pad(srRcpt.szTransName, srRcpt.szTransName, ' ', 21, CENTER);
		LOG_PRINTFF((0x08L, "srRcpt.szTransName : [%s]", srRcpt.szTransName));
	}

		strcpy(srRcpt.szHostName, szGetHostName());

    long2str (srRcpt.szBatchNum, lnGetBatchNum());
    pad (srRcpt.szBatchNum, srRcpt.szBatchNum, '0', inGetBatchNumSize(), RIGHT);

// vdDisplayAt(1,1,srRcpt.szBatchNum, CLR_EOL); get_char(); /* $$$ */
    strcpy(room, pobTran->srBRec.szRoomNum);

    if (strlen(room) > 0)
        strcpy(srRcpt.szInvNum,room);
    else
    if (pobTran->srBKey.fVoided || pobTran->fAdjust || pobTran->fTipAdjust ||
        (pobTran->srBRec.fCloseTabSameCard))
        sprintf(srRcpt.szInvNum, SUBSTITUTE_LD,pobTran->srBKey.lnInvNum);
    else
        sprintf(srRcpt.szInvNum, SUBSTITUTE_LD,pobTran->srBKey.lnInvNum);

    sprintf(srRcpt.unFrm.srReceipt.szSTAN, SUBSTITUTE_LD, pobTran->srBKey.lnOrgSTAN);
    sprintf(srRcpt.unFrm.srReceipt.szECRInvNo, SUBSTITUTE_LD, pobTran->lnECRInvNum);
	pad (srRcpt.szInvNum, srRcpt.szInvNum, '0', 6, RIGHT);  // CITI_PHIL added.


    memset(srRcpt.unFrm.srReceipt.szECRInvNo, 0, sizeof(srRcpt.unFrm.srReceipt.szECRInvNo));


	strcpy(srRcpt.unFrm.srReceipt.szServId,szGetSrvENum());
    //vdGetCDTSENum(srRcpt.unFrm.srReceipt.szServId); //CPAC2.1B

    if (strlen(pobTran->srBRec.szExpDate) > 0)
    {
        strcpy(szExpDate, pobTran->srBRec.szExpDate);
        sprintf(srRcpt.unFrm.srReceipt.szExpDate, "%.2s/%.2s", szExpDate+2, szExpDate);
    }

	if (pobTran->srBRec.inChipStatus==EMV_CARD) {
		memset(szAPPLPrefName, 0x00,sizeof(szAPPLPrefName));
		memset(szAPPLLabel, 0x00,sizeof(szAPPLLabel));
		inGetBatchFieldData(&pobTran->srBRec, CITI_TAG_9F12_APPL_PRE_NAME,(unsigned char *)szAPPLPrefName, 20);
		inGetBatchFieldData(&pobTran->srBRec, CITI_TAG_50_APPL_LABEL,(unsigned char *)szAPPLLabel, 20);
		if(  memcmp((char*)szAPPLPrefName,"CREDITO DE VISA",15) == 0 ) {
			strcpy (srRcpt.unFrm.srReceipt.szApplName,szAPPLPrefName);
		} else {
			strcpy (srRcpt.unFrm.srReceipt.szApplName,szAPPLLabel);
		}
		strcpy (srRcpt.unFrm.srReceipt.szCType,szGetCardLabel());
		LOG_PRINTFF((0x08L, "CARD TYPE : [%s]", srRcpt.unFrm.srReceipt.szCType));
		LOG_PRINTFF((0x08L, "APPL NAME : [%s]", srRcpt.unFrm.srReceipt.szCType));
	} else {
	    //strcpy (srRcpt.unFrm.srReceipt.szCType,szGetIssuerLabel());
		strcpy (srRcpt.unFrm.srReceipt.szCType,szGetCardLabel());  //
		strcpy (srRcpt.unFrm.srReceipt.szApplName, "-");
		//vdGetIssuerLabel(srRcpt.unFrm.srReceipt.szCType);
	}
    if (inGetHDTTotRecs() > 1)
       	strcpy(srRcpt.szHostName, szGetHostName());

    strcpy(srRcpt.unFrm.srReceipt.szCHolder, pobTran->srBRec.szCHolder);
    vdTrimSpaces(srRcpt.unFrm.srReceipt.szCHolder);

#ifdef SHIFT_DEFINED

    if (inGetShiftType() != NO_SHIFT)
        srRcpt.unFrm.srReceipt.chShift = pobTran->srBKey.chShift;
    else
        srRcpt.unFrm.srReceipt.chShift = '0';

#else
		srRcpt.unFrm.srReceipt.chShift = '0';

#endif

}



/*********************************************************************************************
* @func int | inCITIValidateVoid |
*       Checks if the void is allowed.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
* @end
**********************************************************************************************/

int inCITIValidateVoid(TRANSACTION_OBJECT* pobTran) {
    TRANSACTION_OBJECT obTran;
    /* added to incorporate SPBASE2.5 change of 06/16/99 gw */
    int inHDTIndex;

    /* This check must be done before loading batch rec TRT */
    if (inCheckBannedCardType(pobTran) == VS_ERR)
        return(VS_ERR);

    /* Load the correct host */
    /*if (inLoadHostData(inGetCDTHostIndex()) != VS_SUCCESS) ALVARO*/
    if (inLoadDefaultHost(inGetHostHandle()) != VS_SUCCESS)
        return(VS_ERR);

    if (inLoadCDTRec(pobTran->srBRec.inCDTIndex) != VS_SUCCESS)
        return(VS_ERR);

    #ifdef  HDFC_INDIA
    if(fGetBase24CDTVoidAllowed() == VS_FALSE) /*venu_void*/
		{
			vdSGErrorMessage(TRANS_NOT_ALLWD_ERR_MSG);
			return (VS_ERR);
		}
    #endif
    //inHDTIndex = inGetHostGroupID();
    inHDTIndex = inGetHostHandle();

    if (inGCPACHostSelectedIndex != inHDTIndex) {

        vdSGErrorMessage(VOID_NOT_ALLOWED_ERR_MSG);
        return(VS_ERR);
    }

    /* Load TRT locally for batch record    */
    inLoadTRTRec(&obTran, pobTran->srBRec.inCode);

    if (pobTran->srBKey.fVoided) {
        vdSGErrorMessage(ALREADY_VOIDED_ERR_MSG);
        return(VS_ERR);
    }

    /* Check batch record TRT   */
    if (!obTran.srTRTRec.VoidAllowed) {

        vdSGErrorMessage(VOID_NOT_ALLOWED_ERR_MSG);
        return(VS_ERR);
    }

    return (VS_SUCCESS);
}


int inCITIEndModem(TRANSACTION_OBJECT *pobTran)
{
	LOG_PRINTFF((0x08L, "--inCITIEndModem--"));
	obCommunication.inEnd(&obCommunication);
	LOG_PRINTFF((0x08L, "--inCITIEndModem--ENDED"));
	return VS_SUCCESS;
}

void vdFormatPANDisplay(TRANSACTION_OBJECT* pobTran,char* pchPAN,char* pchFmtPAN,int inFmtPANSize) {
    char szFmt[FORMATTED_PAN_SIZE + 1];
    char szScratch[FORMATTED_PAN_SIZE + 1];
    char szCurrentPAN[FORMATTED_PAN_SIZE + 1];
    char chLastPad = ' ';
    VS_BOOL fReverseMode = VS_FALSE;
    VS_BOOL fMerchFormat = VS_FALSE;
    int inBytesLeft;
    int inLen;
    int inLastDigits;
    int inFmtIdx = 0;
    int inPANIdx = 0;
    int i = 0;

    /* Remove 1 from count for NULL terminator, assume caller uses sizeof */
    inFmtPANSize--;

    memset(szFmt, 0x00, sizeof(szFmt));

    if (inGetIssuerRecord(inGetIssuerNum()) == VS_SUCCESS) {
        //strcpy(szFmt, szGetPANFormat());
        //jrd spqalog 31 to display the panformat on recipt only and not on the terminal display
        strcpy(szFmt, "NNNN NNNN NNNN NNNN");
		//strcpy(szFmt, szGetPANFormat());
        fMerchFormat = fGetMerchPANFormat();
    }

    if (strlen(szFmt) == 0 || (pobTran->srBRec.inPrintOption & PRT_MERCH && fMerchFormat == VS_FALSE)) {
        /* No formatting so print the entire account # */
        strlcpy(pchFmtPAN, pchPAN, inFmtPANSize);
        return;
    }

    /* First check on reverse mode, only indicated by first byte */
    memset(szCurrentPAN, 0x00, sizeof(szCurrentPAN));
    if (szFmt[inFmtIdx] == 'R' || szFmt[inFmtIdx] == 'r') {
        fReverseMode = VS_TRUE;
        inFmtIdx++;  /* Move past the 'r' */
        inBytesLeft = inLen = strlen(pchPAN);
        inBytesLeft--;  /* array index starts at 0 */
        for (i = 0; i < inLen && i < FORMATTED_PAN_SIZE; i++,inBytesLeft--) {
            /* Copy the PAN backwards */
            szCurrentPAN[i] = *(pchPAN + inBytesLeft);
        }
    } /* end if reverse mode */
    else
        strlcpy(szCurrentPAN, pchPAN, FORMATTED_PAN_SIZE); /* end else normal mode */


    /* While rcpt.acctnum not full && ! end of PAN  && ! end of Format string */
    while (szFmt[inFmtIdx] != NULL_CH && szCurrentPAN[inPANIdx] != NULL_CH && strlen(pchFmtPAN) < inFmtPANSize) {
        if (szFmt[inFmtIdx] == 'n' || szFmt[inFmtIdx] == 'N') {
            /* They want this one digit in full view */
            append_char(pchFmtPAN, szCurrentPAN[inPANIdx]);
            inFmtIdx++;
            inPANIdx++;
            if (szFmt[inFmtIdx] == NULL_CH)
                inFmtIdx--;
        } /* end if n or N, print PAN digit */
        else if (szFmt[inFmtIdx] == 'X' || szFmt[inFmtIdx] == 'x' || szFmt[inFmtIdx] == '*') {
            /* They want one pad character */
            append_char(pchFmtPAN, szFmt[inFmtIdx]);
            chLastPad = szFmt[inFmtIdx];
            inFmtIdx++;
            inPANIdx++;
            if (szFmt[inFmtIdx] == NULL_CH) {
                /* No more formatting so print the rest w/ pads */
                inBytesLeft = strlen(&szCurrentPAN[inPANIdx]);
                memset(szScratch, 0x00, sizeof(szScratch));
                pad(szScratch, szScratch, chLastPad, inBytesLeft, RIGHT);
                strcat(pchFmtPAN, szScratch);
            }
        } /* end if pad character (x,X or * ) */
        else if (!isdigit(szFmt[inFmtIdx])) {
            /* They want a format separator */
            append_char(pchFmtPAN, szFmt[inFmtIdx]);
            inFmtIdx++;
        } /* end if not 0-9 */
        else if (szFmt[inFmtIdx] == '0') {
            /* Zero is not a valid value */
            inFmtIdx++;
        } /* end if zero */
        else {
            /* We must have 1-9 in szFmt[inFmtIdx] */
            inBytesLeft = strlen(&szCurrentPAN[inPANIdx]);
            inLastDigits = chars2int(&szFmt[inFmtIdx], 1);

            /* if we are reverse mode the last digits are in the front.
             if we are not in reverse then if what we have left in the PAN
             is less than or equal to the LastDigit PAN Format indicator
             if either is true then print a PAN digit in the open */
            if ((fReverseMode && inPANIdx < inLastDigits) || (!fReverseMode && inBytesLeft <= inLastDigits)) {
                append_char(pchFmtPAN, szCurrentPAN[inPANIdx]);
                inFmtIdx++;
                inPANIdx++;
                if (fReverseMode && (inPANIdx < inLastDigits || szFmt[inFmtIdx] == NULL_CH)) {
                    /* Still have more PAN digits to print */
                    inFmtIdx--;
                }
                if (szFmt[inFmtIdx] == NULL_CH) {
                    /* No more formatting so print the rest of the PAN */
                    strcat(pchFmtPAN, &szCurrentPAN[inPANIdx]);
                }
            } /* if last x digits then print the PAN in the open */
            else {
                /* If we are not at the end of PAN then print the last pad char */
                if (chLastPad != ' ')
                    append_char(pchFmtPAN, chLastPad);
                inFmtIdx++;
                inPANIdx++;
                /* if that was our last format character then use it again */
                if (szFmt[inFmtIdx] == NULL_CH)
                    inFmtIdx--;
            } /* end if PAN remaining greater than last digit indicator */
        } /* end else, must be 1-9 */
    } /* end while print buffer not full, not end of Format string or PAN */

    if (fReverseMode) {
        memset(szScratch, 0x00, sizeof(szScratch));
        inBytesLeft = inLen = strlen(pchFmtPAN);
        inBytesLeft--;  /* array index starts at 0 */
        for (i = 0; i < inLen && i < FORMATTED_PAN_SIZE; i++,--inBytesLeft) {
            /* Copy the Formatted PAN back so that it is forward */
            szScratch[i] = *(pchFmtPAN + inBytesLeft);
        }
        strlcpy(pchFmtPAN, szScratch, FORMATTED_PAN_SIZE);
    } /* end if reverse mode */


    return;
} /* end func vdFormatPAN() */

int inCITICustDisplaySwipeCardInfo(TRANSACTION_OBJECT* pobTran) {
    char szFormattedPAN[FORMATTED_PAN_SIZE + 1];
    int inMsgLen,
    inFmtPANLen,
    inGrid,
    inFontType;
    char szMsg[MESSAGE_SIZE + 1],
    szAccountNumber[PAN_SIZE + 1];
	char buff[10];

	memset(buff, 0x00, sizeof(buff));
    memset(szFormattedPAN, 0x00, FORMATTED_PAN_SIZE + 1);
    vdClear_8X21_Window(1, 4, 21, inImamLineNumber);
    strcpy(szAccountNumber, pobTran->srBRec.szPAN);
#ifndef HKGM
#else
    strcpy(szFormattedPAN, szAccountNumber);
#endif /* HKGM */
    //vdFormatPAN(pobTran, szAccountNumber, szFormattedPAN, sizeof(szFormattedPAN));
    //jrd spqalog31 to display panformat of "NNNN NNNN NNNN NNNN" in the terminal instead of panformat in the IIT
    //vdFormatPANDisplay(pobTran, szAccountNumber, szFormattedPAN, sizeof(szFormattedPAN));
	vdFormatPAN(pobTran, szAccountNumber, szFormattedPAN, sizeof (szFormattedPAN));

    vdGetMessageFromFile(CPAC_PAN_MESSAGE, szMsg);
    inMsgLen = strlen(szMsg);
    inFmtPANLen = strlen(szFormattedPAN);

    inGrid = getgrid();
    inFontType = get_font_mode();

    if (inGrid == 0) {
        vdDisplayAt(obDisp.inHomeCol, 3, szMsg, CLR_EOL);
        vdDisplayAt_ASC8X21((22 - (strlen(szFormattedPAN))), 7, szFormattedPAN, NO_CLEAR);
    } else {
        //vdDisplayAt(obDisp.inHomeCol, 5, szMsg, CLR_EOL);
        //vdDisplayAt((22 - (strlen(szFormattedPAN))), 7, szFormattedPAN, CLR_EOL);
		{   //LIEM to display card holder name
			char szCardHolder[CHOLDER_SIZE * 2 + 1];
			strcpy(szCardHolder, pobTran->srBRec.szCHolder);
			vdTrimLeadSpaces(szCardHolder);
			szCardHolder[21] = 0x00;
			vdTrimSpaces(szCardHolder);
			if (strlen(szCardHolder)>1) vdDisplayAt((22 - (strlen (szCardHolder))), inImamLineNumber-3, szCardHolder, CLR_EOL); 
		}	
		//vdDisplayAt(obDisp.inHomeCol, 5, szMsg, CLR_EOL); //
   	    vdDisplayAt(1, inImamLineNumber-2, "PAN:", CLR_EOL);
		if (strlen (szFormattedPAN) > 17) inImamCustScroll(pobTran);
		if (strlen (szFormattedPAN) > 21) {
			strcpy(szFormattedPAN, &szFormattedPAN[strlen(szFormattedPAN)-21]); 
			szFormattedPAN[21] = 0x00;
		}
		/* Edi - wongslam - disable screen pan formated */
    		{
			memset(buff, 0x00, sizeof(buff));
			get_env_x("MASKING.SCREEN", 0, buff);
			if (atoi(buff)) {
				vdDisplayAt((22 - (strlen (szFormattedPAN))), inImamLineNumber-2, szFormattedPAN, CLR_EOL);
			} else {
				vdDisplayAt((22 - (strlen (szAccountNumber))), inImamLineNumber-2, szAccountNumber, CLR_EOL);
			}
    		}
		/*******************************************/
		
		vdDisplayAt(1, inImamLineNumber-1, "EXP[MMYY]:", CLR_EOL);
		memset(buff, 0x00, sizeof(buff));
		strncat(buff, &pobTran->srBRec.szExpDate[2], 2);
		strncat(buff, &pobTran->srBRec.szExpDate[0], 2);
		vdDisplayAt((22 - (strlen (buff))), inImamLineNumber-1, buff, CLR_EOL);
		//inImamCustScroll();  //
    }
    return (VS_SUCCESS);
}


// Added by Andy   May 31, 2004
// for fix on PFR for Settlement
//jrd spqalog021
int inCITIReprintSettleRep(TRANSACTION_OBJECT *pobTran)
{
	SETT_REC srLocSRec;
	SETT_KEY srLocSKey;

	vdSetHDTCustomBit1(VS_FALSE);
	vdSetHDTCustomBit2(VS_FALSE);
	inSaveHDTRec(shGetHostGroupRef());


	//inSMCHPrintSettlementReport(pobTran, VS_FALSE, VS_TRUE, VS_FALSE);
	inPrintSettlementReport(pobTran, VS_FALSE, VS_TRUE, VS_FALSE);

	/* pj1 Add host name to sett_rec and set GDS*/
	inMakeTerminalTotals (pobTran, VS_FALSE, VS_TRUE); //CPAC2.2B
	strcpy(srRcpt.szHostName, szGetHostName());
	//strcpy(srRcpt.szHostName, szGetCUSTName()); // Andy
	vdTrimLeadSpaces(srRcpt.szHostName);

	strcpy (srLocSRec.szHostName, srRcpt.szHostName);
	inPutSettRec(pobTran, &srLocSRec, &srLocSKey);
	  inPurgeHostFromBatch (pobTran, inGetBatchIndex(), VS_TRUE);
	  inPFRStateStoreAll(PFR_IDLE_STATE,pobTran,0,0);

	if (( inResetOfflineCount()) != VS_SUCCESS)
		vdDisplayMessageFromFile( BDT_ERR_MSG, ERROR_MSG);

	if ((inResetAccum()) != VS_SUCCESS)
		vdDisplayMessageFromFile( ACCUM_ERR_MSG, ERROR_MSG);

#ifdef CLERK_DEFINED
		if ((inResult = inResetUTT (pobTran)) != VS_SUCCESS)
			vdDisplayMessageFromFile( UTT_FAIL_ERR_MSG21, ERROR_MSG);

	   /* reset active clerk file bb1 */
		if ((inResult = inResetADT ()) != VS_SUCCESS)
			vdDisplayMessageFromFile( ADT_FILE_ERR_MSG21, ERROR_MSG);

		inResetUDTLogedIn();
#endif /* if CLERK_DEFINED */

		/* Zero the STT File */
#ifdef SHIFT_DEFINED
		if (inResetSTT (pobTran) != VS_SUCCESS)
		{
			vdDisplayMessageFromFile( STT_FAIL_ERR_MSG21, ERROR_MSG);
		}
#endif
	/*
	 *		Must close the batch so that if this function is called again for a different host the correct
	 *		batch will be opened above.
	 */
	vdCloseDCBatch(pobTran);
	vdFree ((char *)pobTran->srBRec.pchHostData);
	pobTran->srBRec.pchHostData = NULL;





	return VS_SUCCESS;
}




int inSettlementFlagTrue(TRANSACTION_OBJECT *pobTran)
{
	fSettmentFlag=VS_TRUE;
	return VS_SUCCESS;
}

int inSettlementFlagFalse(TRANSACTION_OBJECT *pobTran)
{
	fSettmentFlag=VS_FALSE;
	return VS_SUCCESS;
}


/*void citi_hex_2_asc(BYTE *outp, BYTE *inp, int length)
{
int i;

	for(i=0;i<length;i++)
	{
		if((inp[i] >> 4) > 9)
			outp[i*2] = (BYTE) ((inp[i]>>4) + 'A' - 10);
		else
			outp[i*2] = (BYTE) ((inp[i]>>4) + '0');

		if((inp[i] & 0x0f) > 9)
			outp[i*2+1] = (BYTE) ((inp[i] & 0x0f) + 'A' - 10);
		else
			outp[i*2+1] = (BYTE) ((inp[i] & 0x0f) + '0');

	}
	outp[i*2] = 0;

	return;
}*/


int inChangeSaleCompMsgforVoid(TRANSACTION_OBJECT *pobTran)
{
	//jrd Bank Referral

	 char   szBankRef[5 + 1];

     memset(szBankRef, 0, sizeof(szBankRef));
     inGetBatchFieldData(&pobTran->srBRec, CITI_EMV_BANK_REFFERAL, (unsigned char *)szBankRef, 5);


    // if( ((strcmp((char*)srISO.pszField39, "01") == 0)||(strcmp((char*)srISO.pszField39, "02") == 0)) && (pobTran->srBKey.fVoided == VS_FALSE))
     if( ((strcmp((char*)szBankRef, "TRUE") == 0)) && (pobTran->srBKey.fVoided == VS_TRUE)&&(pobTran->srBRec.inCode ==SALE_OFFLINE))
	 {

     		pobTran->srBRec.lnMessage = SALE_OFFLINE_MSG;
	}

	if( ((strcmp((char*)szBankRef, "TRUE") == 0)) && (pobTran->srBKey.fVoided == VS_TRUE)&&(pobTran->srBRec.inCode == REFUND))
	 {

     		pobTran->srBRec.lnMessage = REFUND_OFFLINE_MSG;
	}

	return VS_SUCCESS;
}


int inCITIBankReferral(TRANSACTION_OBJECT *pobTran)
{
	//Bank Referral of Swipe Card

	char szReferralAllow[2];
	memset (szReferralAllow, 0x00, sizeof(szReferralAllow));
	
	if(strcmp(szGetHostFileName(), "JCBI")==0)
	{
		get_env("#JCBIREFERALALWD", szReferralAllow, sizeof(szReferralAllow));
	}
	else
	{
		get_env("#CITIREFERALALWD", szReferralAllow, sizeof(szReferralAllow));
	}
	
		if(pobTran->srBRec.inChipStatus == EMV_CARD)
			return(VS_SUCCESS);

	
	if ((strcmp(pobTran->srBRec.szRespCode, "01") == 0) || (strcmp(pobTran->srBRec.szRespCode, "02") == 0))
        {
             pobTran->srBRec.inTransactionResult = HOST_REFERRAL;
	     if(strcmp(szReferralAllow, "1")!=0)
		{
		 	vdCPACDispRespMsg(pobTran);
	    		return (VS_ERROR);
			
		}
	     //vdCPACDispRespMsg(pobTran);
	     //return (VS_ERROR);
	     
		if((pobTran->srBRec.inTransactionResult==HOST_REFERRAL) &&	((pobTran->srTRTRec.TransactionCode == SALE) || (pobTran->srTRTRec.TransactionCode == REFUND)))
		{

			inEMVReferralProcessing(pobTran);
		}

		
		if((pobTran->fReferral == VS_TRUE) &&	((pobTran->srTRTRec.TransactionCode == SALE) || (pobTran->srTRTRec.TransactionCode == REFUND)))
		{

					//Store this transaction as an offline sale/refund transaction and trickle feed it to the host
					if(pobTran->srTRTRec.TransactionCode == SALE)
					{

	            				//inLoadTRTRec(pobTran, SALE_OFFLINE);
	            				//CITI_BANK_REFERRAL,
						vdSGCode(SALE_OFFLINE);
						pobTran->srTRTRec.Offline = VS_TRUE;
						pobTran->srBKey.fOffline = VS_TRUE;
	            		pobTran->srTRTRec.TransactionCode = SALE_OFFLINE;
						pobTran->srBRec.lnMessage = SALE_COMP_MSG;
					}
					else if(pobTran->srTRTRec.TransactionCode == REFUND)
					{

						inLoadTRTRec(pobTran, REFUND);
						vdSGCode(REFUND);
						pobTran->srTRTRec.Offline= VS_TRUE;
						pobTran->srBKey.fOffline= VS_TRUE;
						pobTran->srBRec.lnMessage = SALE_COMP_MSG;
					}

					inRunFunction(pobTran, BUILD_AND_SEND_PACKET);  //LIEM: NOT USED


		            		//pobTran->srBRec.inTransactionResult = AUTHORIZED;
					inPFRStateStoreAll(PFR_BEGIN_EMV_UPDATE_BATCH ,pobTran,1,1);
					return VS_SUCCESS;

		} 
		else
		{
		 	vdSGErrorMessage(0L);
         	 	vdSGRespMsg("Cancel");
		   	return (BRANCH_EXIT); // KiaSoon 170206: To make sure press CANCEL KEY EXIT
		}

    	}



	return VS_SUCCESS;

	}


int inCITIDisplayAppLabel(TRANSACTION_OBJECT *pobTran)
{
    BYTE    btAPPLPrefName[20];
    BYTE    btAPPLLabel[20];

    unsigned short inDOLen;

	if (pobTran->srBRec.inChipStatus==EMV_CARD) {
		unsigned char btTmp[64];
		char buff[64];
		unsigned short usLen;
		memset(buff, 0x00, sizeof(buff));
		memset(btTmp, 0x00, sizeof(btTmp));
		usEMVGetTLVFromColxn(TAG_4F_AID, btTmp, &usLen);
		inStoreBatchFieldData ((BATCH_REC *)&pobTran->srBRec, FID_EMV_TAG_4F_AID, btTmp, usLen);
		SVC_HEX_2_DSP((char  *)btTmp,buff,8);	
		LOG_PRINTFF((0x08, "TAG4F AID = [%s]", buff));
	}

    if(pobTran->inChipStatus == EMV_CARD)
    {
		memset(btAPPLPrefName, 0x00,20);
		memset(btAPPLLabel, 0x00,20);

		usEMVGetTLVFromColxn(TAG_9F12_APPL_PRE_NAME, (byte *)btAPPLPrefName, (unsigned short *) &inDOLen);
		LOG_PRINTFF((0x08L, "TAG(0x%X): EMVGetTLV[TAG_9F12_APPL_PRE_NAME = %s]", TAG_9F12_APPL_PRE_NAME, btAPPLPrefName));
		usEMVGetTLVFromColxn(TAG_50_APPL_LABEL, (byte *)btAPPLLabel, (unsigned short *) &inDOLen);
		LOG_PRINTFF((0x08L, "TAG(0x%X): EMVGetTLV[TAG_50_APPL_LABEL = %s]", TAG_50_APPL_LABEL, btAPPLLabel));
		inStoreBatchFieldData(&pobTran->srBRec, CITI_TAG_9F12_APPL_PRE_NAME, (unsigned char *)btAPPLPrefName, strlen((char *)btAPPLPrefName));
  		inStoreBatchFieldData(&pobTran->srBRec, CITI_TAG_50_APPL_LABEL, (unsigned char *)btAPPLLabel, strlen((char *)btAPPLLabel));
  		vdDisplayAt(1, inImamLineNumber-5,"  ", CLR_EOL);
		vdDisplayAt(1, inImamLineNumber-4,"APPL:", CLR_EOL);
		if(  memcmp((char*)btAPPLPrefName,"CREDITO DE VISA",15) == 0 ){
			vdDisplayAt((22 - (strlen ((char*)btAPPLPrefName))), inImamLineNumber-4, (char*)btAPPLPrefName, NO_CLEAR);
			//vdDispStrAtRight((char*)btAPPLPrefName, 4, NO_CLEAR);
			LOG_PRINTFF((0x08L, "App Name : [%s]", (char*)btAPPLPrefName));
        } else {
			vdDisplayAt((22 - (strlen ((char*)btAPPLLabel))), inImamLineNumber-4, (char*)btAPPLLabel, NO_CLEAR);
			//vdDispStrAtRight((char*)btAPPLLabel, 4, NO_CLEAR);
			LOG_PRINTFF((0x08L, "App Name : [%s]", (char*)btAPPLLabel));
		}
    }
/*
	{
		BYTE    btAID[16];	// AID selected on chip card (tag 4F)
		char    szRID[50];	// RID of selected AID - as ASCII string
		unsigned short usLen;
		usEMVGetTLVFromColxn(TAG_4F_AID,(byte*)btAID, &usLen);
		hex_2_asc((BYTE *)szRID, btAID, 7);	
		LOG_PRINTFF((0x8L,(char*)szRID));
		if(strncmp((char *)szRID,"A0000000032010",14) == 0) //VISA ELECTRON
	}
*/
	return VS_TRUE;
}

/* LeeChyi - 02122005: START */
/* This function enables the user to select either Dialup or GPRS as the communications media */
int inCITIEditCOMOperation(TRANSACTION_OBJECT *pobTran)
{
   unsigned int inOnOffValue,inEditCom=get_env_int("*EDITCOM");
   char szDisplayBuffer1[DISP_STR_LEN + 1], szDisplayBuffer2[DISP_STR_LEN + 1];

   if(inEditCom == 0)
   	return(BRANCH_EXIT);	
   
   memset(szDisplayBuffer1, 0, sizeof(szDisplayBuffer1));
   memset(szDisplayBuffer2, 0, sizeof(szDisplayBuffer2));
   vdGetMessageFromFile(CITI_SELECT_COM_MSG, szDisplayBuffer1);
   vdGetMessageFromFile(CITI_DIALUP_GPRS_MSG, szDisplayBuffer2);
   
   inOnOffValue = obDisp.inDO_ChooseOne(szDisplayBuffer1, szDisplayBuffer2, (char *) pchGetMsg(CITI_SELECT_1_OR_2_MSG), 2, NULL_PFI);
   
   if(inOnOffValue == 1 || inOnOffValue == 2)
   {
      put_env_int("*RADIO", inOnOffValue);
      vdDisplayMessageFromFile((inOnOffValue==1) ? CITI_INIT_DIALUP_MSG : CITI_INIT_GPRS_MSG, WARNING_MSG);
      SVC_RESTART(""); 
   }
   	
   return(BRANCH_EXIT);
}
/* LeeChyi - END */


// Kia Soon 08122005
// Added for Edit PABX without going into setup
int inCITIEditPABXOper(TRANSACTION_OBJECT *pobTran)
{
  int inRetValue;
  char szResponseString[10];
  char szPABXCode[PABX_CODE_SIZE+1];
  unsigned int inEditExitValue;
  char szDisplayBuffer[DISP_STR_LEN + 1], szDisplayBuffer2[DISP_STR_LEN + 1];
  char szDisplayBuffer3[2];
 
   memset(szDisplayBuffer, 0, sizeof(szDisplayBuffer));
   memset(szDisplayBuffer2, 0, sizeof(szDisplayBuffer2));
    memset(szDisplayBuffer3, 0, sizeof(szDisplayBuffer2));
   vdGetMessageFromFile(CITI_ENTER_PABX_MSG, szDisplayBuffer);
  
  vdClearNonTitleLines();
  inLoadTCTRec(0);
  
   while(1)
   {
   	memset(szDisplayBuffer2, 0, sizeof(szDisplayBuffer2));
   	memset(szPABXCode, 0x00, PABX_CODE_SIZE+1);
  	strcpy(szPABXCode, szGetPABXCode());
  
  	if(strlen(szPABXCode) > 0)
  	  	strcpy(szDisplayBuffer2, szPABXCode);
   	 	
   	
   	inEditExitValue = obDisp.inDO_ChooseOne(szDisplayBuffer, szDisplayBuffer2, (char *) pchGetMsg(CITI_EDIT_EXIT_MSG), 2, NULL_PFI);
   
  	if(inEditExitValue==1)
  	{	
  		if((inRetValue = inEnterWithMessage(CITI_ENTER_PABX_MSG, FALSE, szResponseString, INPUT_ALNUMS, PABX_CODE_SIZE, NULL))>=0);
  		          vdSetPABXCode(szResponseString);	
  		      
  	}
  	else if(inEditExitValue==2)
  	{
  		inSaveTCTRec(0);
  		break;	
  	}
   }
   return(BRANCH_EXIT);
}
// Kia Soon 08122005
// Print the terminal configuration
int inCITIPrintConfigOper(TRANSACTION_OBJECT *pobTran)
{
	CPAC_REC srCPAC;
	char szBuf[50], szBuf1[50];
	int i, j, inNumOfHost;//
	#if 0 
	inf inNumOfMerch, inPlanCnt, inTotalPlans;
	#endif
	//char szMyIPAddress[25+1];
	//short shCommLink;
	int inOrignalHost ;
	int inInstallment=0, inHostNum=0;
	char szMessage[(MESSAGE_SIZE*3)];
	char szDisplay[MESSAGE_SIZE];
	int inResult;
	FHANDLE hFHandle;
	
	memset(szDisplay, 0, MESSAGE_SIZE);
	memset(szMessage, 0, (MESSAGE_SIZE*3));
	inCITIPrintText(" ", PRINT_NORMAL);
	memset(szBuf,0, 30);
	memset(szBuf1,0, 30);
	strcpy(szBuf, "   TERMINAL CONFIG   ");
	inCITIPrintText(szBuf, PRINT_DBL_WIDTH);
	inCITIPrintText(" ", PRINT_NORMAL);
	strcpy(szBuf, "M/No: ");
	SVC_INFO_MODELNO(szBuf1);
	strcat(szBuf, szBuf1);
	inCITIPrintText(szBuf, PRINT_DBL_WIDTH);
	memset(szBuf,0, 30);
	memset(szBuf1,0, 30);
	strcpy(szBuf, "S/No: ");
	SVC_INFO_SERLNO(szBuf1);
	strcat(szBuf, szBuf1);
	inCITIPrintText(szBuf, PRINT_DBL_WIDTH);
	memset(szBuf,0, 30);
	memset(szBuf1,0, 30);
	strcpy(szBuf, "P/No: ");
	SVC_INFO_PARTNO(szBuf1);
	strcat(szBuf, szBuf1);
	inCITIPrintText(szBuf, PRINT_DBL_WIDTH);
	memset(szBuf,0, 30);
	memset(szBuf1,0, 30);
	strcpy(szBuf, "REV : ");
	SVC_INFO_HW_VERS(szBuf1);
	strcat(szBuf, szBuf1);
	inCITIPrintText(szBuf, PRINT_DBL_WIDTH);
	memset(szBuf,0, 30);
	memset(szBuf1,0, 30);
	strcpy(szBuf, "OS  : ");
	SVC_INFO_EPROM(szBuf1);
	strcat(szBuf, szBuf1);
	inCITIPrintText(szBuf, PRINT_DBL_WIDTH);

	strcpy(szBuf, "APPL: BNI02B_V_210611");
	inLoadPCTRec(0);
	strcat(szBuf, szGetRctFoot2());
	inCITIPrintText(szBuf, PRINT_DBL_WIDTH);
	
	
	if ((hFHandle = open("about.txt", O_RDONLY)) < 0)
    	{
    		close(hFHandle);
        	//return(VS_ERR);
    	}
        else
        {
    		memset(szMessage, 0x00, sizeof(szMessage));

    		inResult = read(hFHandle, szMessage, sizeof(szMessage));
    		close(hFHandle);
    		if (inResult != VS_ERROR)              /* Success reading record info */ 
        	{
        		while (szMessage[strlen(szMessage) - 1] < ' ')
        			szMessage[strlen(szMessage) - 1] = NULL_CH;	

       			for(i=0,j=0; i<strlen(szMessage); i++)
       			{
       				if(szMessage[i] == ':' && j!=0)
    				{
    					break;      
    	  			}
    	  			
    				if(szMessage[i] == ':' && j==0) 
    				{
    					j=i;
    	 			}
    			}
        		if(i!=0 && j!=0 && j<i)
       				memcpy(szDisplay, (szMessage+j+1), i-j-1);
       
        		inCITIPrintText(szDisplay, PRINT_DBL_WIDTH);
    		}	
    	}
    	inCITIPrintText(" ", PRINT_NORMAL);
    
	inLoadMITRec(0);
	inNumOfHost = inGetHDTTotRecs();
	inOrignalHost= inGetHostHandle();
	for(i=0; i<inNumOfHost; i++)
	{
		
		vdSetHostHandle(i);
		inLoadHostData(i);
		memset(szBuf, 0, 30); 
		strcpy(szBuf, "HOST: ");
		
		strcat(szBuf, szGetHostName());
		inCITIPrintText(szBuf, PRINT_DBL_WIDTH);
		vdLoadCPACParams(&srCPAC);
		strlcpy(szBuf, "TID : ", 8);
		strcat(szBuf, srCPAC.szCPACTID);
		inCITIPrintText(szBuf, PRINT_DBL_WIDTH);
		memset(szBuf, 0, 30);
		strlcpy(szBuf, "MID : ", 15);
		strcat(szBuf, srCPAC.szCPACMID);
		inCITIPrintText(szBuf, PRINT_DBL_WIDTH);
		inCITIPrintText(" ", PRINT_NORMAL);
	}
	
	inCITIPrintText(" ", PRINT_NORMAL);
	inCITIPrintText(" ", PRINT_NORMAL);
	inCITIPrintText(" ", PRINT_NORMAL);
	inCITIPrintText(" ", PRINT_NORMAL);
	inCITIPrintText(" ", PRINT_NORMAL);
	inCITIPrintText(" ", PRINT_NORMAL);
	
	return VS_SUCCESS;
     
}

int inCITIPrintText(char *szDataPrint, int inMode)
{
	unsigned char lBuf[100];
	int inOffset=0;
	if(inMode== PRINT_NORMAL)
	{
		lBuf[0] = PRINT_NORM;
		inOffset = 1;
	}
	else if(inMode == PRINT_DBL_HEIGHT)
	{
		lBuf[0] = PRINT_NORM;
		lBuf[1] = DBL_HEIGHT;
		inOffset = 2;
	}
	else if(inMode == PRINT_DBL_WIDTH)
	{
		lBuf[0] = PRINT_NORM;
		lBuf[1] = DBL_WIDTH;
		inOffset = 2;
	}
	else if(inMode == PRINT_DBL_HEIGHT_WIDTH)
	{
		lBuf[0] = PRINT_NORM;
		lBuf[1] = DBL_HEIGHT;
		lBuf[2] = DBL_WIDTH;
		inOffset = 3;
	}
	strcpy((char *)&lBuf[inOffset], (const char *)szDataPrint);
	strcat((char *)lBuf, "\n");
	

	if (p3700_print(obPrinter.inHandle, lBuf) < 1)
		return VS_ERR;
	return VS_SUCCESS;
}


//////

int inImamReversalSendReceive(TRANSACTION_OBJECT* pobTran,int inISOSendSize) 
{
    int inRetVal = VS_SUCCESS;
	char szReversalFile[20];
	{
		memset(szReversalFile, 0x00, sizeof(szReversalFile));
        vdGetReversalFileName(szReversalFile, shGetHostGroupRef());
        strcat(szReversalFile, REVERSAL_FILE_EXTN);
        if (inChkFileExist(szReversalFile) == VS_SUCCESS) {
            LOG_PRINTFF((0x08L, "Reversal File = [%s] EXIST", szReversalFile));
		} else {
			LOG_PRINTFF((0x08L, "Reversal File = [%s] NOT EXIST", szReversalFile));
			return (VS_SUCCESS);
		}
	}

    if (obCommunication.inBegin) {
        if (obCommunication.inBegin(&obCommunication, shGetCommunicationIndex(), VS_TRUE) != VS_SUCCESS){
            return(VS_ERR);
        }
	}

    if (obCommunication.inCheck) {
        if (obCommunication.inCheck(&obCommunication) != VS_SUCCESS) {
            return(VS_ERR);
        }
	}

    if (inCPACCreateVariantStruct60() == VS_ERR) {
        vdFree((char *) psrVariant60);
        vdSGErrorMessage(NO_MEM_ERR_MSG);
        return(VS_ERR);
    }
    if (inCPACCreateVariantStruct63() == VS_ERR) {
        vdFreeVariantTables();
        vdSGErrorMessage(NO_MEM_ERR_MSG);
        return(VS_ERR);
    }

	LOG_PRINTFF((0x08L, "--inCPACDoReversal--"));

    if ((psrHostData = psrCreateHostData()) == (HOST_8583_DATA *) NULL_CH) {
        vdFreeHostData(psrHostData);
        vdSGErrorMessage(NO_MEM_ERR_MSG);
        ACTIVITY_LOG("Insufficient Memory 01");
        return (VS_ERR);
    }

    vdGetReversalFileName((char *) stRevFileName, shGetHostGroupRef());
    if ((psrHostData->c8583_data = psrCreateCommData(pobTran, inISOSendSize, VS_TRUE)) == (COMM_8583_DATA *) NULL_CH) {
        vdSGErrorMessage(NO_MEM_ERR_MSG);
        vdFreeISO8583Data(psrHostData);
        ACTIVITY_LOG("Insufficient Memory 01");
        return (VS_ERR);
    }

	psrHostData->c8583_data->transceiver = inImamTxRx8583;  //

#ifdef MODEM
	if (inGetUCLCommLink()==0) {  // to get resp timeout
		MODEM_OBJECT *obModem;
		obModem = (MODEM_OBJECT *)obCommunication.Data;
		psrHostData->c8583_data->comm_timeout         = obModem->shGetRespTimeOut(obModem->srCPT);  // for Response TimeOut
		psrHostData->c8583_data->wait_for_carrier     = obModem->shGetCarrierTimeOut(obModem->srCPT); // for Carier TimeOut
	}
#endif

    ((VALIDATION_STRUCT *) (psrHostData->c8583_data->v_parms))->comm_struct = psrHostData->c8583_data;
	//vdInitializeValidationStruct(pobTran, psrHostData->c8583_data->v_parms);
    /* Added for Custom base resp validation CPAC_VALID */

    psrHostData->c8583_data->validation = (PFI_PVOID_INT) inCPACBaseRespValidation;

    psrHostData->reverse_flag = 0;
    inRetVal = prot_8583(psrHostData->c8583_data, REV_ONLY, psrHostData->c8583_data->comm_timeout);

    vdFreeCommData(psrHostData->c8583_data);
    vdFreeHostData(psrHostData);
    vdFreeVariantTables();

	if (obCommunication.inEnd) obCommunication.inEnd(&obCommunication);
    if (inRetVal > 0)
        inRetVal = 0;
    return(inRetVal);
}
/*
int inImamReversalSendReceive(TRANSACTION_OBJECT* pobTran,int inISOSendSize)
{
	int inRetval = VS_SUCCESS;
    short inMyTranCode;
    short inPIPTransCode;
	char buff[128];
    PACKET_OBJECT obPacket;
	
	DisplayStatus("SENDING REVERSAL...");
	LOG_PRINTFF((0x08L, "IMIDIATE REVERSAL SENT"));
    if (fGetDemoMode() == VS_TRUE) {
        return (VS_SUCCESS);
    }
    if (inCPACCreateVariantStruct60() == VS_ERR) {
        vdFree((char *) psrVariant60);
        vdSGErrorMessage(NO_MEM_ERR_MSG);
        return(VS_ERR);
    }
    if (inCPACCreateVariantStruct63() == VS_ERR) {
        vdFreeVariantTables();
        vdSGErrorMessage(NO_MEM_ERR_MSG);
        return(VS_ERR);
    }
    if ((psrHostData = psrCreateHostData()) == (HOST_8583_DATA *) NULL_CH) {
        vdFreeHostData(psrHostData);
        vdFreeVariantTables();
        vdSGErrorMessage(NO_MEM_ERR_MSG);
        return (VS_ERR);
    }
	inIncSTAN();
    pobTran->srBRec.lnSTAN = lnGetSTAN();

    if (inInitializePacket(&obPacket) != VS_SUCCESS) { //Do we need?
        return(VS_ERR);
    }
    if (obPacket.inInitialize(&obPacket) != VS_SUCCESS) {//Do we need?
        return(VS_ERR);
    }
    if ((psrHostData->c8583_data = psrCreateCommData(pobTran, CPAC_SEND_SIZE, VS_FALSE)) == (COMM_8583_DATA *) NULL_CH) {
        vdSGErrorMessage(NO_MEM_ERR_MSG);
        vdFreeISO8583Data(psrHostData);
        return (VS_ERR);
    }
	psrHostData->c8583_data->transceiver = inImamTxRx8583;  //
#ifdef MODEM
	if (inGetUCLCommLink()==0) {  // to get resp timeout
		MODEM_OBJECT *obModem;
		obModem = (MODEM_OBJECT *)obCommunication.Data;
		psrHostData->c8583_data->comm_timeout         = obModem->shGetRespTimeOut(obModem->srCPT);  // for Response TimeOut
		psrHostData->c8583_data->wait_for_carrier     = obModem->shGetCarrierTimeOut(obModem->srCPT); // for Carier TimeOut
	}
#endif
    ((VALIDATION_STRUCT *) (psrHostData->c8583_data->v_parms))->comm_struct = psrHostData->c8583_data;
	psrHostData->c8583_data->validation = (PFI_PVOID_INT) inCPACBaseRespValidation; 

	obPacket.inError = 0;			

	vdDispMsgAt(WAIT_MSG, 1, inImamLineNumber, CLR_EOL);
	errno = 0;

    vdGetReversalFileName((char *) stRevFileName, shGetHostGroupRef());
    psrHostData->reverse_flag = 0;
    inRetVal = prot_8583(psrHostData->c8583_data, REV_ONLY, psrHostData->c8583_data->comm_timeout);

	vdFreeISO8583Data(psrHostData);
	if (inRetVal > 0)
        inRetVal = 0;
	return(inRetVal);
}
*/
